Click here to Skip to main content
15,915,848 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
plz help!
i want write an insert statement from data of table1 to table2 with a condition in table3.i mean if there is a data on table3 insert data from table2 to table1.
how i can wite it?
Posted
Comments
Anil Honey 206 17-Oct-11 4:45am    
Question is not clear?

SQL
if exists(select * from table3 where id=4)
begin

  INSERT INTO table2(field1, field2)
  SELECT field1, field2
  FROM table1  

end
 
Share this answer
 
SQL
INSERT INTO @Table1 (ID)
(SELECT B.id from @Table2 A, @Table3 B where A.ID=B.ID)


You may also use any joins to develop your result set & use it on your select query
 
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