I have 3 variables which will be conditional when @path is not NULL i.e
@serverName,@analysisDB,@cubeName. Hence I used a CASE statement in the above SELECT statement. Similarly, for @path is not NULL the @cubename also needs to be conditional for LVL5.L5_CubeName (see REPLACE statement) but its inside a REPLACE statement and the CASE block becomes too complicated for the same. How do I write it if I want to do something like
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
Something like this: