Below is an example of code that I have, and I would like it to print a user's account number along with a each procedure number and the sequence number that shows up for that appointment, for example:
acc num proc num Seq num
--------------------------------
Vxxxxxxxxx26 44.42 1
Vxxxxxxxxx26 57.94 2
Vxxxxxxxxx26 57.32 3
Vxxxxxxxxx26 38.93 4
But instead it prints many duplicates of the same thing for the same date and time, for example:
acc num proc num Seq num
--------------------------------
Vxxxxxxxxx26 44.42 1
Vxxxxxxxxx26 57.94 2
Vxxxxxxxxx26 57.32 3
Vxxxxxxxxx26 38.93 4
Vxxxxxxxxx26 44.42 1
Vxxxxxxxxx26 57.94 2
Vxxxxxxxxx26 57.32 3
Vxxxxxxxxx26 38.93 4
Vxxxxxxxxx26 44.42 1
Vxxxxxxxxx26 57.94 2
Vxxxxxxxxx26 57.32 3
Vxxxxxxxxx26 38.93 4
How can I limit it so it only shows 1 set of values rather than 5 set of values?
BTW I am a newbie to Stack Overflow and SQL so please keep that in mind when reviewing. Thank you.
NOTE: It seems as though it is the OeOrders
table. When this is not JOINED it has the appropriate rows, when it is JOINED it expands with all the multiple rows.
CODE
DECLARE
@StartDate DateTime,
@EndDate DateTime
SET @StartDate = '10/28/2013 00:00:000'
SET @EndDate = '11/28/2013 23:59:000'
SET @RecordType = '6'
SELECT
,AbstractData.AccountNumber AS AcctNum_2
,'I9:'+AbsDrgProcedures.DrgProcedure AS ProcCode_3
,AbsDrgProcedures.ProcedureSeqID AS Priority_4
FROM AbstractData
LEFT JOIN AbsDrgProcedures
ON (AbsDrgProcedures.VisitID = AbstractData.VisitID) AND AbsDrgProcedures.VisitID IS NOT NULL
LEFT JOIN OeOrders
ON (OeOrders.VisitID = AbstractData.VisitID)
WHERE
AbstractData.PtStatus <> 'REF'
AND OeOrders.ServiceDateTime BETWEEN @StartDate and @EndDate
Select distinct results - SELECT DISTINCT
rather than SELECT
.