SELECT I.*, M.* FROM OPENROWSET('SQLOLEDB', '192.168.10.2'; 'sa'; '123', [Database1].[dbo].[Table1]) I INNER JOIN ( SELECT DISTINCT P.IPSAppID AppId, P.DepartmentId, C.CategoryId, T.Creator FROM OPENROWSET('SQLOLEDB', '192.168.10.1'; 'sa'; '123', [Database2].[dbo].[table2]) P LEFT JOIN ( SELECT DISTINCT LTRIM(DepartmentId) DepartmentId, UserName Creator FROM OPENROWSET('SQLOLEDB', '192.168.10.1'; 'sa'; '123', [Database3].[dbo].[view1]) WHERE UserName IN (SELECT DISTINCT Creator FROM OPENROWSET('SQLOLEDB', '192.168.10.1'; 'sa'; '123', [Database1].[dbo].[Table1]) WHERE AppId = '8cefca00-9733-4976-951a-e19346603717' AND CategoryId = 'b14b4852-c0e4-4db6-a91e-704b699a8fa2') ) T ON P.DepartmentId = T.DepartmentId LEFT JOIN OPENROWSET('SQLOLEDB', '192.168.10.1'; 'sa'; '123', [Database2].[dbo].[Table3]) C ON C.AppId = P.IPSAppID WHERE P.ClassId IS NULL AND T.Creator IS NOT NULL AND C.CategoryName = 'activity') M ON M.Creator = I.Creator WHERE I.AppId = '8cefca00-9733-4976-951a-e19346603717' AND I.CategoryId = 'b14b4852-c0e4-4db6-a91e-704b699a8fa2'
posted on 2010-05-12 17:34 封起De日子 阅读(166) 评论(0) 编辑 收藏 举报