Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I came with a case where i need help either i can do it in one uqery:I have to segregate members data for 1st year anniversary, 3rd year Anniversary, 5 yrs, 10 years and so on as per the joining date till 31 may 2015.And with in each year i have to divide the counts between no of activities for 1 year, 2 years, 3 yeards and so on...Please help me if it can be done?Do it your own way
James K
Master Smack Fu Yak Hacker
3873 Posts
Posted - 2015-04-20 : 08:32:51
Yes, it can be done - something like this:
SELECT SUM( CASE WHEN DATEADD(yy, 1,MemberStartDate) < GETDATE() THEN 1 ELSE 0 END) AS MembersLessThanAYear, SUM( CASE WHEN DATEADD(yy, 2,MemberStartDate) < GETDATE() AND DATEADD(yy, 1,MemberStartDate) >- GETDATE() THEN 1 ELSE 0 END) AS MembersBetween1and2Years, ....