Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to update one table(main table) from a another temp_table


table1(main table)

billno. name address date fun
A1001 [null] [null] [null] ABC
B1002 [null] [null] [null] BCA
A1004 [null] [null] [null] BAC


table2(temp table)

name address date fun billno.
qqq wwww 10/11/11 ABC A1001
wee tttt 21/10/12 BCA B1002
trrr oooo 11/09/21 BAC A1004

i have two common fields fun n billno.
UPDATE from TEMPtable to MAIN table.
now i can to update name address date of main table .
and condition is i want to update only 'A100'


for that i can see the values

select * from temp_table where billno like 'A100%'


but i need to update only A100 rows in main table from temptable

table1(main table) OUTPUT

billno. name address date fun
A1001 qqq wwww 10/11/11 ABC
B1002 [null] [null] [null] BCA
A1004 trrr oooo 11/09/21 BAC
Posted

You may use trigger concept and play with magic table,however trigger is not good practice,you may attemp different approach also

you may go to below link

http://stackoverflow.com/questions/12137102/sql-update-trigger-only-when-column-is-modified[^]

Triggers -- SQL Server[^]
 
Share this answer
 
Try this:
SQL
UPDATE t1 SET t1.[name] = t2.[name], t1.address = t2.address, t1.[date] = t2.[date]
FROM table1 as t1 INNER JOIN table2 AS t2 ON t1.billno = t2.billno
WHERE t1.billno Like 'A100%'
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900