Hey everyone, this one is just making me crazy.
I have a table (custSales) with the following columns:
custType, Period, Sales
Now I would like to create a crosstab, like so:
Select custType,
Sum(case Period when 'TY' then Sales else null end) As ThisYear,
Sum(case Period when 'LY' then Sales else null end) As LastYear
From custSales
Group By custType
This works...sort of...I get the values I want but like this:
custType ThisYear Lastyear
Bookstore NULL 523.14
Bookstore 847.35 NULL
In other words, it gives me a separate line for each one instead of putting on the same line like this:
custType ThisYear LastYear
Bookstore 847.35 523.14
Can anyone see what's wrong with my statement? What am I doing wrong?
Thanks a bunch!
prgmrgirl
I have a table (custSales) with the following columns:
custType, Period, Sales
Now I would like to create a crosstab, like so:
Select custType,
Sum(case Period when 'TY' then Sales else null end) As ThisYear,
Sum(case Period when 'LY' then Sales else null end) As LastYear
From custSales
Group By custType
This works...sort of...I get the values I want but like this:
custType ThisYear Lastyear
Bookstore NULL 523.14
Bookstore 847.35 NULL
In other words, it gives me a separate line for each one instead of putting on the same line like this:
custType ThisYear LastYear
Bookstore 847.35 523.14
Can anyone see what's wrong with my statement? What am I doing wrong?
Thanks a bunch!
prgmrgirl