Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL Server
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 1:04am
Rate this: bad
good
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
 
http://stackoverflow.com/questions/12137102/sql-update-trigger-only-when-column-is-modified[^]
 
Triggers -- SQL Server[^]
  Permalink  
Rate this: bad
good
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%'
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 Sergey Alexandrovich Kryukov 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 22 Jul 2014
Copyright © CodeProject, 1999-2014
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