question

m.rezaei avatar image
m.rezaei asked

How to update many records with different values from another table

Actually I have two tables as following:

t1(orderid,batchnumber,gtin,expdate,password);

t2(orderid,batchnumber,gtin,expdate);

t1 has 1000 records with only password and other fields has null values

t2 has 1000 diferent records

Now I,m looking for a way to update t1 null values with t2 values

sql-serverjoinsscriptupdate_query
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
m.rezaei avatar image
m.rezaei answered

My problem has solved by following script:

with cts as(
select row_number() over (order by id) as row#, ordercode,batchnumber from tempBarcodes 
)
update barcodes set orderid=c.ordercode,batchNumber=c.batchNumber from cts c
inner join barcodes b 
on c.row#=b.id
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.