Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rosmiq
Starting Member
5 Posts |
Posted - 2010-08-26 : 07:44:18
|
I am joining 2 tables using the FULL OUTER JOIN. For each job ref you may get multiple lines of equipment used. The equipment field will list all the types of equipment, i.e:JobRef Equipment12345 Type112345 Type212345 Type223456 Type1This will display on multiple lines. I need to be able to count how many types of equipment for each job. I want it to be displayed like the following:JobRef Count of Type1 Count of Type212345 1 223456 1 0I am using reporting services SSRS2005 and would like to know how I need to do this.Can anybody please help?Many thanksrosmiq |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-08-26 : 09:48:33
|
SELECT JobRef ,SUM(CASE WHEN Equipment = 'Type1' THEN 1 ELSE 0 END) as Type1 ,SUM(CASE WHEN Equipment = 'Type2' THEN 1 ELSE 0 END) as Type2JimEveryday I learn something that somebody else already knew |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-08-26 : 09:49:59
|
quote: Originally posted by jimf
SELECT JobRef ,SUM(CASE WHEN Equipment = 'Type1' THEN 1 ELSE 0 END) as Type1 ,SUM(CASE WHEN Equipment = 'Type2' THEN 1 ELSE 0 END) as Type2FROM YourTableNameHerePleaseGROUP BY JobRef
N 56°04'39.26"E 12°55'05.63" |
 |
|
rosmiq
Starting Member
5 Posts |
Posted - 2010-08-26 : 10:30:10
|
Thank you for your replies, it worked a treat!!!! :-) |
 |
|
|
|
|