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
 Anniversay Data Division

Author  Topic 

drunkenneo
Starting Member

3 Posts

Posted - 2015-04-20 : 02:20:02
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,
....
Go to Top of Page
   

- Advertisement -