Bubbalouie
Technical User
I am attempting to perform some math on the results of a datediff operation for a helpdesk report.
In simplified terms I want my result set to look similar to this:
gets me the data I'm after, but I want to count those tickets by the Dept, Category and how many days open the ticket was. I just can't get them together. I think I need to count the datediff results using a case statement somehow. I've tried every which way to do so but the only result I get is 'syntax error...............).
Anyway, if it's not possible to do this I'll inform the boss but if it is possible and someone can show me the light I'd be most grateful!
In simplified terms I want my result set to look similar to this:
Code:
Dept Category 0_Days 1-2_Days 3-4_Days Over_4_Days
ADMIN Hardware 2 3 1 1
ADMIN Software 3 1 1 1
ADMIN Internet 1 0 0 0
ADMIN Email 2 1 0 1
FINANCE Hardware 1 0 3 0
FINANCE Software 2 2 1 0
FINANCE Intranet 1 2 0 1
SALES Email 1 0 1 0
SALES Telephone 2 0 0 0
Code:
select p.department, p.category, datediff(d, p.start_date, p.close_date) as Days_Open from dbo.problems p
order by p.department, p.category
gets me the data I'm after, but I want to count those tickets by the Dept, Category and how many days open the ticket was. I just can't get them together. I think I need to count the datediff results using a case statement somehow. I've tried every which way to do so but the only result I get is 'syntax error...............).
Anyway, if it's not possible to do this I'll inform the boss but if it is possible and someone can show me the light I'd be most grateful!