January 2, 2014 at 4:14 am
Hi,
I have this sql....
SELECT
dbPatID, dbAddDate, dbStaffLastName, RefTypeWord
FROM
EPSReferralKPIs
WHERE
(dbAddDate >= '2013-01-01' OR '2013-01-01' = '')
AND (dbAddDate <= '2013-12-31' OR '2013-12-31' = '')
AND (dbStaffLastName IN ('Swanepoel','Patient','Pelletti','Ray','Qureshi','Grobler','Hedborg','De Kock','Lima','Check In','Hodgson')
AND (RefTypeWord IN ('PATIENT','OTHER','DOCTOR','','SIBLING')
ORDER BY
dbAddDate
There may be more than one RefTypeWord for a dbPatId however I only want the result set to bring back unique dbPatID's and not more than one row containing a different RefTypeWord per row.
Is that possible?
thanks,
January 2, 2014 at 4:43 am
What about the other columns? Can you show a few rows of what you have and what you would like to see? Remember - we can't see what you can, we're relying upon your description.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 2, 2014 at 4:53 am
The current sql will bring back
900032592013-05-28 16:05:13.000GroblerDOCTOR
900032592013-05-28 16:05:13.000GroblerOTHER
Where as I want it to bring back just one row for each dbPatID, I'm not bothered which RefTypeWord it is
thanks
January 2, 2014 at 4:59 am
Try this as a test:
SELECT
dbPatID,
dbAddDate,
dbStaffLastName,
RefTypeWord = MAX(RefTypeWord)
FROM EPSReferralKPIs
WHERE
dbAddDate >= '2013-01-01' OR '2013-01-01' = ''
AND dbAddDate <= '2013-12-31' OR '2013-12-31' = ''
AND dbStaffLastName IN ('Swanepoel','Patient','Pelletti','Ray','Qureshi','Grobler','Hedborg','De Kock','Lima','Check In','Hodgson')
AND RefTypeWord IN ('PATIENT','OTHER','DOCTOR','','SIBLING')
GROUP BY dbPatID, dbAddDate, dbStaffLastName
ORDER BY dbAddDate
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 2, 2014 at 5:26 am
Thanks, I've actually worked out we don't need to select the RefTypeWord, so removing this from the select and making dbPatID distinct bought back the correct amount of rows.
I compared this with your sql and it brings the same result set back which is good.
thanks for your help.
January 2, 2014 at 5:52 am
Just a thought...what's this meant to do?
(dbAddDate >= '2013-01-01' OR '2013-01-01' = '')
AND (dbAddDate <= '2013-12-31' OR '2013-12-31' = '')
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply