if exists(select * from table3 where id=4) begin INSERT INTO table2(field1, field2) SELECT field1, field2 FROM table1 end
INSERT INTO @Table1 (ID) (SELECT B.id from @Table2 A, @Table3 B where A.ID=B.ID)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)