📜  如果表存在,则 sql server union - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:22.110000             🧑  作者: Mango

代码示例1
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