简体   繁体   中英

using name value pair to update record in database - sql server

Have been looking this up in Google but could not find anything.

Wanted to know if there is a way in SQL Server 2005 that I could use Name Value pairs to update records in the db.

I have a list of Name Value pairs and want to update all the records where Name could be found as a columm value (something that you would specify in where clause) and if the record is found ... update the record with the Value paired with the name

For instance, something like

update X set column_value = <Value paired with the Name> where column_name = <Name from the list>

PS I have a list of more than 1000 records and this could be more.

The obvious way is to store your pair values in separate table. Eg :

map(name,value)

And update your table using join. Eg :

update m1 set m1.column_value = m2.value
from mytable m1 join map m2 on m1.column_name = m2.name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM