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 |
inbs
Aged Yak Warrior
860 Posts |
Posted - 2013-06-03 : 14:01:51
|
i have this tableEventkey EventDateKey Filekey10 1-1-2013 120 2-1-2013 1 30 3-1-2013 140 4-1-2013 1 i want to get this tableFileKey EventKey_10 Eventkey_20 EventKey_30 EventKey_401 1-1-2013 2-1-2013 3-1-2013 4-1-2013 |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-06-03 : 14:52:34
|
[CODE]DECLARE @TEMP2 AS TABLE(EventKey INT, EventDateKey Date, FileKey INT);INSERT INTO @TEMP2 VALUES(10, '1-1-2013', 1);INSERT INTO @TEMP2 VALUES(20, '2-1-2013', 1);INSERT INTO @TEMP2 VALUES(30, '3-1-2013', 1);INSERT INTO @TEMP2 VALUES(40, '4-1-2013', 1);SELECT FileKey, [10] as EventKey_10, [20] as EventKey_20, [30] as EventKey_30, [40] as EventKey_40 FROM (SELECT FileKey, EventDateKey, EventKey FROM @TEMP2) AS D PIVOT(MAX(EventDateKey) FOR EventKey IN([10], [20], [30], [40])) AS P;[/CODE] |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|