powerpivot将两个DB转换为单个表

时间:2015-04-21 19:58:33

标签: sql-server powerpivot

我有一个查询来管理同一台服务器上两个不同数据库的结果:

SELECT DISTINCT
        DB1.Table1.ProjectName ,
        CAST(DB1.Table1.ProjectFinishDate AS DATE) AS 'FinishDate' ,
        DB1.Table1.ProjectOwnerName AS 'ProjectOwner'
FROM    DB1.Table1 
WHERE   DATEDIFF(MONTH,CURRENT_TIMESTAMP,DB1.Table1.ProjectFinishDate) < 7
        AND DB1.Table1.ProjectPercentCompleted < 100
UNION
SELECT DISTINCT
        DB2.Table1.ProjectName ,
        CAST(DB2.Table1.ProjectFinishDate AS DATE) AS 'FinishDate' ,
        DB2.Table1.ProjectOwnerName AS 'ProjectOwner'
FROM    DB2.Table1 
WHERE   DATEDIFF(MONTH,CURRENT_TIMESTAMP,DB2.Table1.ProjectFinishDate) < 7
        AND DB2.Table1.ProjectPercentCompleted < 100
ORDER BY CAST(Table1.ProjectFinishDate AS DATE)

查询在SQL中运行良好,但我需要将结果作为单个表在Excel中显示。但是,由于它位于两个不同的数据库中,因此我无法将其作为单个数据连接的输出。我试图将输出提取到PowerPivot中,因为它似乎应该允许我这样做,但我也无法在那里工作。

有人可以告诉我是否有办法吗?

感谢。