Below is the query I am using to list a patients Admit Date. I want to be able to compare the listed Admit Date to the patient's previous admission date (based on the Unit Number) to see if they were here <= 30 days ago.
The query is currently pulling the Max(AdmitDateTime) as the previous date. I need it to be the last admission before the current one.
Can someone rewrite the MS-Access SQL as SQL Server 2008 syntax?
SELECT T.UnitNumber, T.AccountNumber, T.AdmitDateTime, Max(T2.AdmitDateTime) AS PrevAdmitDate
AS T LEFT JOIN qry_Lace_Last_Admit_30Days
AS T2 ON T.UnitNumber = T2.UnitNumber
GROUP BY T.UnitNumber, T.AccountNumber, T.AdmitDateTime;
I have attached a sample of the data I am getting.