Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用where子句将两个表中的数据合并到一个表中_Sql_Sql Server_Database - Fatal编程技术网

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-谢谢,我没看到;