I’ve two table:
Table A
ID Field1 ….
Table B
ID Field2 Field3 …
I would like to LOOP through table B and if a a record with same ID exits in table A, add the value Field2 and Field3 in Table A.
I don’t know how to do in T-SQL!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using a loop construction is not necessary for this update, you can solve it in a neater way by using set operations. If I understand the question correctly you want to UPDATE table A with the values from table B. Use a query like this:
You might wanna do an extra check in this query to see what the values in field 2 and 3 in table A are before replacing them.
(To test first what the results of this query will be, build a SELECT query from the UPDATE query above!)