Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friends

I have two tables t1,t2

data in t1 is

insert into t1(id,name,address) values (1,Sunil,gurgaon)
insert into t1(id,name,address) values (2,Ashok,Delhi)

1 Sunil Narnaul
2 Ashok Narrajnaul


data in table t2

insert into t2(id,name) values (1,Sunil)
insert into t2(id,name) values (2,Ashok)

1 Sunil NULL
2 Ashok NULL

Now I want to insert addess of table t1 into address of table t2 at present values in address of t2 is null.
Pls send me query for this.

Pls Help me out
Posted

If you just want to populate the data from address column in table t1 into address of corresponding row of t2, (i mean just to transfer the data) you can try the cursors in sql[^] way.

The Sql cursors should be kept a last option before using them as a part of stored procedures.


HTH
Rajeev


Please vote and mark the answer as accepted if this helps
 
Share this answer
 
Would this work for you?
SQL
update t2
set address=t1.address
from t2
join t1 on t2.id=t1.id
where t2.address is null
 
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