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 |
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2008-12-16 : 04:07:50
|
| HiI have a table that looks like this...ID Partno Lang1 1234 GB2 1234 ES3 1234 FI4 4567 ES5 4567 SE6 7889 GBIs it possible to retrieve a result like this..Partno Lang_GB Lang_ES Lang_FI Lang_SE1234 1 1 1 04567 0 1 0 1789 1 0 0 0Best Regards |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-12-16 : 04:29:12
|
| Read about PIVOT operator in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-16 : 04:37:10
|
| [code]SELECT Partno,SUM(CASE WHEN Lang='GB' THEN 1 ELSE 0 END) AS Lang_GB,SUM(CASE WHEN Lang='ES' THEN 1 ELSE 0 END) AS Lang_ES,SUM(CASE WHEN Lang='FI' THEN 1 ELSE 0 END) AS Lang_FI,SUM(CASE WHEN Lang='SE' THEN 1 ELSE 0 END) AS Lang_SEFROM tableGROUP BY Partno[/code] |
 |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2008-12-16 : 04:43:00
|
| Excellent, just what I was looking for, Thanks ! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-16 : 04:46:06
|
Welcome |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2008-12-16 : 04:54:00
|
| SELECT partno,GB as 'lang_gb',ES as 'lang_es',FI as 'lang_fi',SE as 'lang_se'from ( select * from string ) as ipivot ( count(id) for lang in ( GB,ES,FI,SE)) as pI Struggle For Excellence |
 |
|
|
|
|
|
|
|