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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Reding Colom names from table to use in UPDATE?

Author  Topic 

Kagen101
Starting Member

5 Posts

Posted - 2005-09-30 : 02:30:09
I have a function that returns a table, that I want to use to Update another table. The one colom is the colom name in the other table and the other colom is the value that the colom must change to.
So we have this

idx colName Value
0 col1 a
1 col2 b
2 col3 c

I then construct a update query as follows and lets say the table it updates is called MyTable:
So I first select the colom name and value from the above table(all variables have been declared):

SELECT @tempColName = colName, @tempVal = value FROM @tempTable WHERE idx=1
"idx is and int"

UPDATE MyTable SET @tempColName = @tempVal WHERE someCol = something

It then tells me the rows have been effected but when I query the table it is still exactly like it was.

Any idees why it does this and of a work around?

Thanx

K

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-10-01 : 00:07:04
Post the exact code you're using please. This isn't working for anyone. Think about what you're doing in this example. Set @tempColName????

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-01 : 02:40:17
Are you trying to read data from one table and want to update it with other table?
If so, here is a general approach

Update T1 set T1.col=T2.col from table1 T1 inner join table2 T2 on T1.primarycol=T2.primarycol

Otherwise you need to give some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -