luvmy2kids
MIS
I have the below code:
'Week1' = case when checkdate = dateadd(wk,-4, '2009-9-04') then ISNULL(d.units,0) else 0 end,
'Week2' = case when checkdate = dateadd(wk,-3, '2009-9-04') then ISNULL(d.units,0) else 0 end,
'Week2' = case when checkdate = dateadd(wk,-2, '2009-9-04') then ISNULL(d.units,0) else 0 end,
'Week4' = case when checkdate = dateadd(wk,-1, '2009-9-04') then ISNULL(d.units,0) else 0 end
I want to return one line with each week across the top like this:
Week1 Week2 Week3 Week4
1 2 3 4
Because I have to include the checkdate in my group by clause, it displays my results as:
Week1
Week2, etc.
How can I write my case statements so I won't have to include checkdate in the group by clause. I can't do a sum because it will return incorrect results
Thanks a bunch!!!
'Week1' = case when checkdate = dateadd(wk,-4, '2009-9-04') then ISNULL(d.units,0) else 0 end,
'Week2' = case when checkdate = dateadd(wk,-3, '2009-9-04') then ISNULL(d.units,0) else 0 end,
'Week2' = case when checkdate = dateadd(wk,-2, '2009-9-04') then ISNULL(d.units,0) else 0 end,
'Week4' = case when checkdate = dateadd(wk,-1, '2009-9-04') then ISNULL(d.units,0) else 0 end
I want to return one line with each week across the top like this:
Week1 Week2 Week3 Week4
1 2 3 4
Because I have to include the checkdate in my group by clause, it displays my results as:
Week1
Week2, etc.
How can I write my case statements so I won't have to include checkdate in the group by clause. I can't do a sum because it will return incorrect results
Thanks a bunch!!!