Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sql #server #union #table #exist
ADD COMMENT
Topic
Name
8+8 =