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 |
|
kashyapsid
Yak Posting Veteran
78 Posts |
Posted - 2010-04-26 : 01:35:17
|
| SUM(CASE WHEN custid = 'A' THEN qty END) AS Acould any explain abt the query i didn't understand i read in a book plz help i can't get itKaShYaP |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-04-26 : 01:46:32
|
| Post the full query!Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
kashyapsid
Yak Posting Veteran
78 Posts |
Posted - 2010-04-26 : 01:47:25
|
| SELECT empid, SUM(CASE WHEN custid = 'A' THEN qty END) AS A, SUM(CASE WHEN custid = 'B' THEN qty END) AS B, SUM(CASE WHEN custid = 'C' THEN qty END) AS C, SUM(CASE WHEN custid = 'D' THEN qty END) AS DFROM dbo.OrdersGROUP BY empidKaShYaP |
 |
|
|
kashyapsid
Yak Posting Veteran
78 Posts |
Posted - 2010-04-26 : 01:47:43
|
| this is the full queryKaShYaP |
 |
|
|
kashyapsid
Yak Posting Veteran
78 Posts |
Posted - 2010-04-26 : 01:57:37
|
| A B C D1 NULL 20 34 NULL2 52 27 NULL NULL3 20 NULL 22 30The output is thisKaShYaP |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-26 : 01:58:00
|
| its basically group the data based on empid then taking sum of qty field conditionally based on value of custid. So this will actually give you total qty value for each empid based on custod value in different columnsie likeEmpID A B C D1000 12 4 13 25...this is called cross tabbing------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
kashyapsid
Yak Posting Veteran
78 Posts |
Posted - 2010-04-26 : 02:12:28
|
| i think another name is pivorting is it correctKaShYaP |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-26 : 02:21:15
|
| yup..both are same...cross tabbing and pivoting------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
kashyapsid
Yak Posting Veteran
78 Posts |
Posted - 2010-04-26 : 02:24:16
|
| ok tnksKaShYaP |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-26 : 03:49:22
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|