我希望避免重写下面的相同查询(对于每个唯一的表):
Insert Into dbo.DatabaseNEW (Field1 , Field 2)
Select Field 1, Field 2 FROM OldDatabase.dbo.[Table 1] WHERE DESCRIPTION LIKE 'Something';
Insert Into dbo.DatabaseNEW (Field1 , Field 2)
Select Field 1, Field 2 FROM OldDatabase.dbo.[Table 2] WHERE DESCRIPTION LIKE 'Something';
我尝试过如下组合查询,但它不起作用:
Insert Into dbo.DatabaseNEW (Field1 , Field 2)
Select Field 1, Field 2 FROM OldDatabase.dbo.[Table 1], OldDatabase.dbo.[Table 2] WHERE DESCRIPTION LIKE 'Something';
有任何帮助吗?抱歉,这个菜鸟问题。谢谢!
答案 0 :(得分:1)
您可以使用UNION ALL运算符
Insert Into dbo.DatabaseNEW (Field1 , Field2)
(
Select Field1, Field2 FROM OldDatabase.dbo.[Table 1] WHERE DESCRIPTION LIKE 'Something'
UNION ALL
Select Field1, Field2 FROM OldDatabase.dbo.[Table 2] WHERE DESCRIPTION LIKE 'Something'
);