I need some help constructing a select sql server statement. Some background: I'm working on a Electronic Medical Records application and I need to select records of patients that fit a certain set of conditions. For instance they need to be a certain race, age, gender and if they fit that criteria they are recommended to have a certain procedure preformed. The catch is if they had that procedure done recently then they don't qualify for that procedure. Here is what I have so far and if someone wants to take this on and help me out I'd appricaite it. SELECT P.ChartNumber, P.LastName, P.FirstName, P.Sex, P.DateofBirth, P.Race, MAX(Pr.Date) as Date , Pr.Type, Pr.Code, Pr.PrDx, DATEDIFF ( yy , P.DateofBirth , GETDATE() ) as age FROM MMPatient as P inner Join dbo.MMCHDxRxLtMt as Pr on P.chartnumber=Pr.ChartNumberWhere Pr.Code = 93000 AND P.Race = 'Asian' And Sex = 'Male' And DATEDIFF ( yy , P.DateofBirth , GETDATE()) > = 40Group BY P.ChartNumber, P.LastName, P.FirstName, P.Sex, P.DateofBirth, P.Race, Pr.Code , Pr.Type, Pr.PrDx
This script gives me a list of patients that have had the procedure 93000. It gives me the most recent procedure they have had. Now what I'm trying to do is take each record and see if a year has passed since they have had that procedure. so I want to use something like this. DateADD(ww, 52, Pr.Date) > = GetDate()
I'm just having trouble incorporating the two. Any help would be appreciated.