SELECT 'ULTIPRO_MDUSG0002' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0002].DBO.vw_rbsUserLoginHistorywhere SourceType =
'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0027' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0027].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0028' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0028].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0050' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0050].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0051' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0051].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0071' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0071].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0072' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0072].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0073' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0073].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0074' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0074].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0075' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0075].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0076' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0076].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0077' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0077].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0078' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0078].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0079' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0079].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0080' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0080].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0081' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0081].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0082' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0082].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0084' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0084].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0089' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0089].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0090' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0090].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0091' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0091].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0096' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0096].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0155' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0155].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0156' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0156].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0157' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0157].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0158' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0158].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0159' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0159].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0182' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0182].DBO.vw_rbsUserLoginHistorywhere SourceType = 'MOBILE'
UNION
答案 0 :(得分:0)
您可以尝试创建这样的视图。通过仅在此源上执行查询,将其余部分添加到它的底部(在where
之前还需要一个空格),可以稍微提高速度。
CREATE VIEW AllHistory
AS
SELECT 'ULTIPRO_MDUSG0002' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0002].DBO.vw_rbsUserLoginHistory where SourceType =
'MOBILE'
UNION ALL
SELECT 'ULTIPRO_MDUSG0027' AS dbname
,max(EventDate)
FROM [ULTIPRO_MDUSG0027].DBO.vw_rbsUserLoginHistory where SourceType = 'MOBILE'
UNION ALL
--the rest of them here..
然后
SELECT *
FROM AllHistory