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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 denormalize table

Author  Topic 

damegu
Starting Member

5 Posts

Posted - 2014-08-27 : 05:25:49
Hello,
I would like to know if it is possible to do a SELECT statement where I can denormalize my table. I am not sure if it is needed to create a new table at first and insert denormalized values into the created table.


example
original table:
ID XXX VALUES
1 a 10
1 b 15
1 c 8

And I want to use SELECT to get this table:
ID a b c
1 10 15 8

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-08-27 : 06:12:13
[code]
SELECT *
FROM (
SELECT ID, XXX, VALUES
FROM original_table
) d
PIVOT
(
MAX(VALUES)
FOR XXX IN ([a], [b], [c])
) p
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -