create table #tableA(id int, val varchar(50)) create table #tableB(id int, val varchar(50)) create table #tableC(id int, val varchar(50)) create table #tableD(id int, val varchar(50)) insert into #tableB values (1, '11'); insert into #tableB values (2, '22'); I want insert value for #tableD and my condition is
if
#tableAhas a value theninsert into #tableD select * from #tableA;if
#tableAis empty theninsert into #tableD select * from #tableB;if
#tableAand#tableBare empty theninsert into #tableD select * from #tableC;
How can I do this the simplest way?