Click here to Skip to main content
13,088,101 members (69,352 online)
Rate this:
Please Sign up or sign in to vote.
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 22-Jul-14 0:04am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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[^]

Triggers -- SQL Server[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Try this:
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%'

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 22 Jul 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100