Sunday, February 1, 2015

how to use pivot in between to select query

You can do this in a single query without using PIVOT:



SELECT [OnTime] = SUM(CASE WHEN DATEDIFF(MINUTE, T.[Paydate], T.[DelDate]) < 1 THEN 1 ELSE 0 END)
,[Violate] = SUM(CASE WHEN DATEDIFF(MINUTE, T.[Paydate], T.[DelDate]) > 1 THEN 1 ELSE 0 END)
FROM [Transaction_tbl] T
WHERE T.[Locid] = 6
AND T.[Status] = 5





- Vishal


SqlAndMe.com



No comments:

Post a Comment