SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-08-13 : 03:21:00
|
[code]DECLARE @Sample TABLE ( Item CHAR(7) NOT NULL, Grp TINYINT NOT NULL, Price MONEY NOT NULL );INSERT @Sample ( Item, Grp, Price )VALUES ('0000001', 102, 164.9000), ('0000001', 103, 164.9000), ('0000001', 106, 161.8000), ('0000003', 100, 164.9000), ('0000003', 102, 164.9000), ('0000003', 103, 164.9000), ('0000003', 106, 161.8000), ('0000007', 100, 164.9000), ('0000007', 102, 164.9000), ('0000007', 103, 164.9000), ('0000007', 106, 161.8000), ('0000008', 100, 164.9000), ('0000008', 102, 164.9000), ('0000008', 103, 164.9000), ('0000008', 106, 161.8000);-- SwePesoSELECT p.Item, p.[100] AS Group100, p.[102] AS Group102, p.[103] AS Group103, p.[106] AS Group106FROM @Sample AS sPIVOT ( MAX(s.Price) FOR s.Grp IN ([100], [102], [103], [106]) ) AS p;[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|