Sql 使用where子句将两个表中的数据合并到一个表中
我有两个文件,我已经批量导入到两个日期重叠的表中。现在我想将两个表中的数据移动到一个新表中,但要删除重叠的日期。这是我的代码:Sql 使用where子句将两个表中的数据合并到一个表中,sql,sql-server,database,Sql,Sql Server,Database,我有两个文件,我已经批量导入到两个日期重叠的表中。现在我想将两个表中的数据移动到一个新表中,但要删除重叠的日期。这是我的代码: -- Pull across data from P1-10 and exclude out of scope dates SELECT * INTO I_Inventory FROM I_Inventory_P10_Temp WHERE [date] >= '01/01/2016' and [date] <
-- Pull across data from P1-10 and exclude out of scope dates
SELECT *
INTO I_Inventory
FROM I_Inventory_P10_Temp
WHERE [date] >= '01/01/2016' and [date] <= '10/31/16'
-- Pull across data from P11-12 and exclude out of scope dates
SELECT *
INTO I_Inventory
FROM I_Inventory_P12_Temp
WHERE [date] >= '11/01/2016' and [date] <= '12/31/16'
但是,这不起作用,因为它表示在第一次选择进入之后,表已经存在。有人能告诉我怎么做吗?我对SQL非常陌生。使用UNION ALL组合结果,然后插入到表中
SELECT *
INTO I_Inventory
FROM I_Inventory_P10_Temp
WHERE [date] >= '01/01/2016' and [date] <= '10/31/16'
Union All
-- Pull across data from P11-12 and exclude out of scope dates
SELECT *
FROM I_Inventory_P12_Temp
WHERE [date] >= '11/01/2016' and [date] <= '12/31/16'
查看UNION ALL。两个不同的表,所以前两个查询不起作用。@jarlh-谢谢,我没看到;