How to Update from Single Row/Many columns to Single Column/Many Rows
In SQL Server2000
I want to try to create a stored procedure that uses the following select statement which pulls all the column names from a single row in a table: We'll Call it A
SELECT name
FROM syscolumns
WHERE [id] = OBJECT_ID('dbo.A')
To create a Recordset and then Join those records to rows in an existing table (Lets Call it B) that has a field called eField which holds all the names of these columns
I then want to take the values from Table A and update them into a corresponding field eValue in B .
Basically this is a transformation but I don't know the syntax I want to take a row of values and turn them into a column of values.
Here's Table A
Folder ID Apples Peaches Plums
_______________________________________
000011 Red Yellow Purple
I want to insert it into this table B
FruitID Color
__________________________
Apple
Peaches
Plums
and End Up with
FruitID Color
__________________________
Apple Red
Peaches Yellow
Plums Purple
By Grabbing the Colum Names from A and matching them to the Values in B.FruitID
And Update B.Color to the Values in Table A Where FolderID = 000011
I hope I am making sense.
Thanks Beforehand
AJ
In SQL Server2000
I want to try to create a stored procedure that uses the following select statement which pulls all the column names from a single row in a table: We'll Call it A
SELECT name
FROM syscolumns
WHERE [id] = OBJECT_ID('dbo.A')
To create a Recordset and then Join those records to rows in an existing table (Lets Call it B) that has a field called eField which holds all the names of these columns
I then want to take the values from Table A and update them into a corresponding field eValue in B .
Basically this is a transformation but I don't know the syntax I want to take a row of values and turn them into a column of values.
Here's Table A
Folder ID Apples Peaches Plums
_______________________________________
000011 Red Yellow Purple
I want to insert it into this table B
FruitID Color
__________________________
Apple
Peaches
Plums
and End Up with
FruitID Color
__________________________
Apple Red
Peaches Yellow
Plums Purple
By Grabbing the Colum Names from A and matching them to the Values in B.FruitID
And Update B.Color to the Values in Table A Where FolderID = 000011
I hope I am making sense.
Thanks Beforehand
AJ