Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Select Script Help

Author  Topic 

mnq
Starting Member

4 Posts

Posted - 2009-03-17 : 14:48:42
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.ChartNumber
Where Pr.Code = 93000 AND P.Race = 'Asian' And Sex = 'Male' And DATEDIFF ( yy , P.DateofBirth , GETDATE()) > = 40
Group 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.

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-17 : 14:59:43
You can add the same in your select..

SELECT   
...
YournewColumn=case when getdate()-Pr.Date > 365 then 'over 1 year' else 'in last one year' end
FROM MMPatient ...
Go to Top of Page
   

- Advertisement -