Click here to Skip to main content
15,915,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I get the minimum date for a visit. I am trying to get the first time the person had a visit. This is for my entire person listing.
Here is my query:
SQL
Declare @dateDate as DateTime
Set @dateDate = SYSDATETIME()

select distinct a.PatientName,
       a.PatientSSN,
       CONVERT(Date, @dateDate) AS FIRSTVISIT
from    SPatient.SPatient as a
    JOIN OUTPAT.VISIT AS D
        ON A.PATIENTSID=D.PATIENTSID
    join Dim.Location as c
        on D.LocationSID=c.LocationSID
where c.locationname like '%wi-%'
      and c.LocationName not like '%wi-PHONE%'
      and c.LocationName not like '%non va%'
      and c.LocationName not like '%ds%'
group by a.patientname, a.patientssn
order by a.patientname, a.patientssn
Posted
Updated 29-Jan-14 10:06am
v3
Comments
TryAndSucceed 29-Jan-14 15:36pm    
If you have the date stored in DB based on the login and for the user, then just get Top 1 based on the user in Ascending order.
Kornfeld Eliyahu Peter 29-Jan-14 15:59pm    
The information you gave is too few to give you a valuable advice. Please improve you question with more details about your situation - optionally with some code and/or data sample - and where you stuck...
King Fisher 31-Jan-14 1:44am    
show you table structure and info

1 solution

Try using the MIN Function

SELECT PatientName, Location, Min(visitdate)
from mytable
group by PatientName, Location
 
Share this answer
 
Comments
Maciej Los 20-Feb-14 17:27pm    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900