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 2008 Forums
 Transact-SQL (2008)
 Creating dynamic Update Query usng othr table rows

Author  Topic 

rafeequddin_ahmed
Starting Member

23 Posts

Posted - 2011-09-29 : 10:17:20
Hi,

I have a table where we keep the column name,old value ,new value and key and the talbe name , for the same key of a table we can have multipe row. I need to create single update statment by using multipe rows.

A table

ID ProcessID columnname oldvalue newvalue Key tablename
1 201 slv 2 4 234 Silver
2 201 des Used selected 234 Silver
3 201 unit 1 3 234 Silver

I have to create a update query as below for the above three records

Update Silver set slv = 4,des = 'selected',unit = 3 where Key = 234

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-29 : 12:25:47
no other way other than to use dynamic sql unless your column and table names are fixed

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -