Answers for "sql server union if table exist"

SQL
0

sql server union if table exist

DECLARE @temp TABLE(empName varchar(100),empStoreNum varchar(100),empSales int,location varchar(20))
if object_id('table1') Is not null
insert into @temp
Select empName, empStoreNum, empSales, 'East' As SalesDistrict
FROM store1

if object_id('table2') is not null
insert into @temp
Select empName, empStoreNum, empSales, 'East' As SalesDistrict
FROM store2

if object_id('table3') is not null
insert into @temp
Select empName, empStoreNum, empSales, 'East' As SalesDistrict
FROM store3


select empName, empStoreNum, empSales,location
from @temp
Posted by: Guest on August-18-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language