Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

UPDATE Columns

$
0
0

How do I UPDATE multiple columns (Code1, Code2, Code3, Code4) from another table.

I have an interim table contain the fields along with Row number, example shown below.

Id            dob                                                 code     descr                                    ROW

8844       1942-05-03 00:00:00.0000000     C712      CREATE OF LENS              1

8844       1942-05-03 00:00:00.0000000     C751      INSERTION OF LENS       2

9398       2014-06-30 00:00:00.0000000     C751      INSERTION OF LENS       1

Using the table shown above I want to UPDATE my main table using the values in the code column to update the COLUMNS

Below is an example of the Main table (which needs updating).

Id	Name        dob                     Code1 Code2 Code3 Code4
8844    John Smith  1942-05-03 00:00:00.000              

So I can I create an UPDATE query so the Main table above will populate the Columns (Code1 to 4) using the results in the interim table. I know I need to join on ID and date of birth.

Below is my attempt at creating the UPDATE query, but code do update the remaining code columns in one go?

updateMainTable

setcode1= code

fromMainTable a

leftouterjoin Interim_Table bon a.id =b.idcollatedatabase_defaultanda.dob=b.dob



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>