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 |
|
w1102157
Yak Posting Veteran
80 Posts |
Posted - 2012-07-16 : 08:34:43
|
| Hi guyskind of a similar question to what i asked before, i have been assked to present data in a certain way,i have extracted the data as belowPr cost Type key GCW 244 EL 1 Dj CW 22 NL 2 Dj IM 24 EL 3 Dj IM 140 NL 4 Dj CW 100 EL 5 DRk CW 23 NL 6 DRk IM 45 EL 7 DRk IM 40 NL 8 DRk CW 46 EL 9 DRS CW 23 NL 10 DRS IM 23 EL 11 DRS IM 12 NL 12 DRS CW 10 EL 13 DZACW 0 NL 14 DZAIM 0 EL 15 DZAIM 0 NL 16 DZAhowever the manager wants me to present this as belowG key [CW EL] [CW NL] [Im El] [im NL]Dj 1 244 22 25 40DRk 2 100 23 45 40DRS 3 46 23 23 12DZA 4 10 0 0 0can anyone help me scrip this?thank you |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-16 : 09:43:30
|
| [code]SELECT G,ROW_NUMBER() OVER (ORDER BY MIN([Key])) AS [Key],SUM(CASE WHEN Pr='CW' AND Type='EL' THEN cost ELSE 0 END) AS [CW EL],SUM(CASE WHEN Pr='CW' AND Type='NL' THEN cost ELSE 0 END) AS [CW NL],SUM(CASE WHEN Pr='CW' AND Type='EL' THEN cost ELSE 0 END) AS [im EL],SUM(CASE WHEN Pr='CW' AND Type='NL' THEN cost ELSE 0 END) AS [im NL]FROM tableGROUP BY G[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|