tsql - How to looping trough a Table, find a value and insert if exists? -


i've 2 table: table id field1 ....

table b id field2 field3 ...

i loop through table b , if a record same id exits in table a, add value field2 , field3 in table a.

i don't know how in t-sql! can me ? thanks

using loop construction not necessary update, can solve in neater way using set operations. if understand question correctly want update table values table b. use query this:

update tablea   set tablea.field2 = tableb.field2, tablea.field3 = tableb.field3   tableb   tablea.id = tableb.id 

you might wanna check in query see values in field 2 , 3 in table before replacing them.

(to test first results of query be, build select query update query above!)


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -