Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Update from Single Row/Many columns to Single Column/Many Row

Status
Not open for further replies.

ajacode

Technical User
Aug 21, 2002
66
US
In SQL Server2000

I want to try to create a trigger or at least 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.

I hope I am making sense.

Thanks Beforehand

AJ
 
AFter Further Review....

I'm Not sure I stated my Problem correctly

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 by using

SELECT name
FROM syscolumns
WHERE [id] = OBJECT_ID('dbo.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 that is a bit clearer..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top