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 2008 Forums
 Transact-SQL (2008)
 SSMS DATEDIFF

Author  Topic 

kond.mohan
Posting Yak Master

213 Posts

Posted - 2012-04-11 : 08:14:04
I WANT TO FIND THE DATEDIFF B/W TO COLUMN

ONE OF COLUMN NEED TO FETCH THE MAX(ABC.DATE) COLUMN

----DATEDIFF(DD,MAX(ABC.DATE),DFS.LCHG_TIME)

STEP 2.

I NEED TO CALCULATE COUNT OF THESE DAYS

---COUNT(DATEDIFF(DD,MAX(ABC.DATE),DFS.LCHG_TIME))

HAVING MAX(ABC.DATE)>DFS.LCHG_TIME

STEP3

COUNT(DATEDIFF(DD,MAX(ABC.DATE),DFS.LCHG_TIME)) BETWEEN 1 AND 5 SHOULD SHOW 1 COUMN
COUNT(DATEDIFF(DD,MAX(ABC.DATE),DFS.LCHG_TIME)) BETWEEN 6 AND 10
SHOULD SHOW 1 COUMN
COUNT(DATEDIFF(DD,MAX(ABC.DATE),DFS.LCHG_TIME)) BETWEEN 11 AND 20
SHOULD SHOW 1 COUMN



FINAL EXPECTED STRUCTURE IS


COUNTOFDAYS 1-5 6-10 11-20 MORETHAN20
10 3 1 2 4
20 4 10 3 3
50 5 15 15 15


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-12 : 00:52:27
can you post some sample data from table and explain what you want? thats much better than posting code part

currently it sounds like what you need is pivot or cross tabbing

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

Go to Top of Page
   

- Advertisement -