question

gpr avatar image
gpr asked

Query to copy 2 two column data to differenct tables...

Query to copy 2 two column data to differenct tables... I have a table emp with columns: emp:-Here seqno starting from 100001 for group by each itemno. Also unique_no starting from (seq_no*100)+1 for each item, iname itemno iname dno seqno unique_no 123 a 10 100001 100001001 123 b 20 100001 100001002 234 a 40 100002 100001201 235 a 10 100003 100001301 235 b 10 100003 100001302 235 z 30 100003 100001303 NOw i want the seqno and unique_no to be update to all other tables which have seqno and unique_no as colummns. Dept:- itemno iname location_key seqno unique_no 123 a 11 __ __ 123 b 23 __ __ 234 a 24 __ __ 235 a 33 __ __ 235 b 55 __ __ 235 z 80 __ __ Store table:- itemno mat_key location_key seqno unique_no 123 a 11 __ __ 123 b 23 __ __ 234 a 24 __ __ 235 a 33 __ __ 235 b 55 __ __ 235 z 80 __ __ simillarly for remaining tables.
sqlserver 2008
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

·
ThomasRushton avatar image
ThomasRushton answered
.Sounds like you just need a series of UPDATE...FROM statements. eg: UPDATE d SET d.seqno = e.seqno, d.unique_no = e.unique_no FROM dept AS d INNER JOIN emp e ON d.itemno = e.itemno AND d.iname = e.iname untested. See documentation at https://docs.microsoft.com/en-us/sql/t-sql/queries/update-transact-sql#OtherTables for more.
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.