March 24, 2004 at 12:43 am
I have the following table schema
ReportCounty ( ID, ReportID, CountyID, Price )
Now i want the following output
ReportID County1 Couty2 Couty3 ......
1 Price Price Price
2 Price Price Price
3 Price Price Price
So on.
Pls help me in making the query
Prashant Thakwanithakwani_prashant@yahoo.co.in
March 24, 2004 at 4:33 am
select ReportId,
SUM( CASE WHEN CountryId = 1 THEN PRICE ELSE 0 END) AS COUNTRY1 ,
SUM( CASE WHEN CountryId = 2 THEN PRICE ELSE 0 END) AS COUNTRY2 ,
SUM( CASE WHEN CountryId = 3 THEN PRICE ELSE 0 END) AS COUNTRY3
from ReportCountry
GROUP BY ReportId
Add as many CASE as you want. If you are not sure how many, switch to dynamic SQL.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply