在case语句中污染功能需要长时间运行完整查询。这是我的查询。有什么建议吗?
SELECT DISTINCT
a.IndexID,
a.IndexShortName,
a.IndexCode,
a.SourceCode,
b.sourcecode,
CASE
WHEN a.IndexID = b.IndexID
AND a.sourcecode = b.sourcecode
AND CONVERT(VARCHAR(10), b.[ModifiedDatetime], 101) = '11/14/2017'
THEN 'Y'
ELSE 'N'
END AS IndexDM_Load,
CASE
WHEN a.SourceIndexID = CONVERT(VARCHAR(10), c.indexID)
AND CONVERT(VARCHAR(10), c.[ModifiedDatetime], 101) = '11/14/2017'
AND a.SourceIndexID = CONVERT(VARCHAR(10), d.indexID)
AND CONVERT(VARCHAR(10), d.[ModifiedDatetime], 101) = '11/14/2017'
AND a.SourceIndexID = e.RIMESSource + e.RIMESIndexSymbol
AND CONVERT(VARCHAR(10), e.FileLoadTime, 101) = '11/14/2017'
AND a.SourceIndexID = f.Source + f.Symbol
AND CONVERT(VARCHAR(10), f.FileLoadTime, 101) = '11/14/2017'
AND a.SourceIndexID = CONVERT(VARCHAR(10), g.indexID)
AND CONVERT(VARCHAR(10), g.FileLoadTime, 101) = '11/14/2017'
AND a.SourceIndexID = CONVERT(VARCHAR(10), h.indexID)
AND CONVERT(VARCHAR(10), h.FileLoadTime, 101) = '11/14/2017'
AND a.SourceIndexID = CONVERT(VARCHAR(10), k.indexID)
AND CONVERT(VARCHAR(10), k.FileLoadTime, 101) = '11/14/2017'
AND a.SourceIndexID = CONVERT(VARCHAR(10), l.indexID)
AND CONVERT(VARCHAR(10), l.FileLoadTime, 101) = '11/14/2017'
THEN 'Y'
ELSE 'N'
END AS Staging_Load
FROM [IndexDM].[dbo].[IndexReference] a
LEFT JOIN [IndexDM].[dbo].[IndexReturn] b ON a.IndexID = b.IndexID
AND a.sourcecode = b.sourcecode
LEFT JOIN [IndexDM].staging.MSCIDailyReturn c ON a.SourceIndexID = CONVERT(VARCHAR(10), c.indexID)
LEFT JOIN [IndexDM].staging.MSCIIndexReference d ON a.SourceIndexID = CONVERT(VARCHAR(10), d.indexID)
LEFT JOIN [IndexDM].staging.RIMESIndexConstituents e ON a.SourceIndexID = e.RIMESSource + e.RIMESIndexSymbol
LEFT JOIN [IndexDM].staging.RIMESIndexValues f ON a.SourceIndexID = f.Source + f.Symbol
LEFT JOIN [IndexDM].staging.RussellGlobalDailyConstituents_Dev_Top_200 g ON a.SourceIndexID = CONVERT(VARCHAR(10), g.indexID)
LEFT JOIN [IndexDM].staging.RussellGlobalDailyConstituents_Dev_Top_200CAD h ON a.SourceIndexID = CONVERT(VARCHAR(10), h.indexID)
LEFT JOIN [IndexDM].staging.RussellGlobalDailyHoldings k ON a.SourceIndexID = CONVERT(VARCHAR(10), k.indexID)
LEFT JOIN [IndexDM].staging.RussellUSIndexReturns l ON a.SourceIndexID = CONVERT(VARCHAR(10), l.indexID);