我有 3 个变量,它们在不为 NULL 时@path
是有条件的,即
@serverName,@analysisDB,@cubeName
。因此,我CASE
在上面的语句中使用了一个SELECT
语句。同样, for@path
不是 NULL@cubename
也需要有条件的 for LVL5.L5_CubeName
(参见REPLACE
语句),但它在REPLACE
语句内部并且CASE
块变得太复杂了。如果我想做类似的事情,我该怎么写
CASE WHEN @path!='' THEN @cubeName ELSE LVL5.L5_CubeName in the REPLACE statement
SELECT LVL5.L5_Id,
CASE WHEN @path!='' THEN @serverName ELSE LVL5.L5_ServerName END [AnalysisServer],
CASE WHEN @path!='' THEN @analysisDB ELSE LVL5.L5_AnalysisDatabase END [AnalysisDatabase],
REPLACE(REPLACE(REPLACE(LVL5.L5_MDXQuery,'@@Level1',ISNULL(@lvl1DataVal,'')),
'@@Level2',ISNULL(@lvl2DataVal,'')),'@@CubeName',ISNULL(@cubeName,'')) [MDXQuery],
LVL5.L5_ReplaceMDX [ReplaceMDX],
LVL5.L5_RefreshDate [RefreshDate],
LVL5.L5_ReportAttribute [ReportAttribute],
LVL5.L5_ReportTitle [ReportTitle]
FROM Report_SR_Level5 [LVL5]
WHERE L4_ID = @L4_ID ORDER BY LVL5.L5_DisplayOrder