I have the SQL below. It gives the list of Accounts that are recurring.
dbo.VisitPT_All_DIS D WITH (NOLOCK)
INNER JOIN dbo.VisitPT_All_DIS R WITH (NOLOCK)
ON D.MRN = R.MRN
INNER JOIN dbo.MedDCStatusVisitPt_All_DIS M WITH (NOLOCK)
ON R.Account = M.Account
AND M.DischargeAction IN ('CONV', 'NEW')
LEFT OUTER JOIN dbo.PROCVISITPT_ALL_DIS P WITH (NOLOCK)
ON D.Account = P.Account
D.AccountStatus_PatientType IN ('DIS_IN', 'DIS_INO', 'DEP_ER' )
AND D.AdmitDateTime >= '01/01/2013'
AND (DATEDIFF(Day, R.AdmitDateTime, D.DischargeDateTime) BETWEEN 0 and 30)
AND R.AccountStatus_PatientType IN ('DIS_IN', 'DIS_INO', 'DEP_ER')
--AND D.MRN = 'LU00247168'
I need to get the list of above MRN, and get ALL the previous acitivity. I need to loop it back to dbo.VisitPT_All_DIS view and get all the Historical data for the MRN #'s returned from the above query. How do I do this?