0

我希望避免重写下面的相同查询(对于每个唯一表):

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';

有什么帮助吗?对不起菜鸟问题。谢谢!

4

1 回答 1

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'
);
于 2013-10-06T15:42:38.663 回答