Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to update from an existing table to another existing table using asp.net

table 1 have values.



table 2 have some null values..


i want to update table 2 comparing similar fields.
update those null values in table 2 .
i will copy from table1 to table2 (null fields)
and also mention the datatype..
table 2
date datetime

table1
data varchar(20)
Posted
Comments
CHill60 23-Jul-14 12:17pm    
How are the tables linked?
10923679 23-Jul-14 12:22pm    
both have common Fields ..
table1
emplyeecode
abc
bca

table 2
emplyeeid
abc
bca
What is your issue?

1 solution

The construct you need is similar to this
SQL
UPDATE t2
SET t2.field1=t1.field1, t2.field2=t1.field2, etc
FROM table1 AS t1
INNER JOIN table2 as t2 ON t1.emplyeecode=t2.emplyeeid and t1.abc=t2.abc -- might be more
WHERE ... -- insert any condition here
 
Share this answer
 
Comments
10923679 24-Jul-14 5:19am    
thank you so much its working..

can u help me with one more problem


i m also trying to update from one table to another
updating null values of table2 from table1


now my problem is

table1
date is varchar

table2
date is datetime

it is nt getting update .

any solution for this.
ASP.net
CHill60 24-Jul-14 15:51pm    
Try t2.datefield=cast(t1.datefield AS DATE)
10923679 1-Aug-14 5:06am    
ok.thnq

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