Creating a temporary table
-
Hi, I have a table which looks like the following.
OriginalTable
OriginalTable_Id(pk) OriginalTable_Name(unique)1 NewColumnName1
2 NewColumnName2
...I need to make it look like this table below dynamically:
NewTable
NewTable_Id(pk) NewColumnName1 NewColumnName2 ...I know I need to create a new tempory Table (using tempDB?), but I don't know how to get the values in the table to be the new column names. I have this at the moment:
CREATE TABLE NewTable
(
NewTable_Id INT PRIMARY KEY,???
)
???: Would it be something like:
SELECT OriginalTable_Name FROM OriginalTable
Any tutorials or advice would be greatly appreciated. Thanks in advance.hmmm pie
-
Hi, I have a table which looks like the following.
OriginalTable
OriginalTable_Id(pk) OriginalTable_Name(unique)1 NewColumnName1
2 NewColumnName2
...I need to make it look like this table below dynamically:
NewTable
NewTable_Id(pk) NewColumnName1 NewColumnName2 ...I know I need to create a new tempory Table (using tempDB?), but I don't know how to get the values in the table to be the new column names. I have this at the moment:
CREATE TABLE NewTable
(
NewTable_Id INT PRIMARY KEY,???
)
???: Would it be something like:
SELECT OriginalTable_Name FROM OriginalTable
Any tutorials or advice would be greatly appreciated. Thanks in advance.hmmm pie
Have a look at pivot clause here[^] Regards, Syed Mehroz Alam
My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein
-
Have a look at pivot clause here[^] Regards, Syed Mehroz Alam
My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein
Brilliant, that's exactly what I was looking for thanks alot. But how can I get the name of the columns dynamically. eg. The value is '198' so how can I make it the column name without knowing the value? Edit: Thanks again for your help. Two minutes after posting this reply and Googleing 'Dynamic Pivots' I found this[^] which solved my problem. Sorry for the inconvenience.
hmmm pie
modified on Wednesday, April 22, 2009 2:15 PM