sql server union if table exist

Solutions on MaxInterview for sql server union if table exist by the best coders in the world

showing results for - "sql server union if table exist"
Emelie
03 Aug 2016
1DECLARE @temp TABLE(empName varchar(100),empStoreNum varchar(100),empSales int,location varchar(20))
2if object_id('table1') Is not null
3insert into @temp
4Select empName, empStoreNum, empSales, 'East' As SalesDistrict
5FROM store1
6
7if object_id('table2') is not null
8insert into @temp
9Select empName, empStoreNum, empSales, 'East' As SalesDistrict
10FROM store2
11
12if object_id('table3') is not null
13insert into @temp
14Select empName, empStoreNum, empSales, 'East' As SalesDistrict
15FROM store3
16
17
18select empName, empStoreNum, empSales,location
19from @temp
20
similar questions
queries leading to this page
sql server union if table exist