我有两个独立的Server数据库,我想查询和比较结果。
例如:
DB1
Select *
from Customers
where dtcreated > @startdate此查询将给出在特定日期之后创建的客户列表。
然后,我想获取上面的结果,并查询另一个数据库(DB2),告诉我上面哪些查询客户仍然处于活动状态。
类似于:
DB2
Select *
From Customers
Where bactive = 'True'
(and exists in DB1 query)有办法这样做吗?
输出:
Number of Records from DB1 Number Active in DB2
155 67发布于 2015-04-01 11:46:31
您可以通过指定数据库名和架构+表名来执行跨数据库查询。
Select *
From Customers b
Where bactive = 'True'
and exists
(Select 'x' from
database1.dbo.Customers A
where a.dtcreated > @startdate
and a.key = b.key)对不起,我对示例查询和示例输出感到有点困惑。但是使用这种技术你可以用任何你喜欢的方式来计算
发布于 2015-04-01 11:48:03
你可以试试这个:
Select *
From db2.dbo.Customers
Where bactive = 'True'
and exists(Select * from db1.dbo.Customers where dtcreated > @startdate)https://stackoverflow.com/questions/29389850
复制相似问题