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
 General SQL Server Forums
 New to SQL Server Programming
 T-SQL script

Author  Topic 

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2011-11-29 : 11:42:24
Hi ,

Need help to write the script.


We are storing User DiseaseDiagnosisDate in yyyy/mm
SELECT userid, DiseaseDiagnosisDate
FROM user

Ex:-

Userid DiseaseDiagnosisDate
1 200901
2 200701
3 199302
4 198501


Now I need to write a script to pull Duration of disease (less than 6 months vs. greater than or equal to 6 months)

Please help. Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-29 : 11:48:14
[code]
SELECT UserId,
CASE
WHEN DATEDIFF(mm,CAST(CAST(DiseaseDiagnosisDate AS varchar(6)) + '01' as datetime),GETDATE()) <6 THEN 'Less than 6 months'
ELSE 'greater than or equal to 6 months'
END AS DurationOfDisease
FROM table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -