开发者

SSRS2008 - SELECT in a CASE...WHEN...THEN

I am using a hidden internal Parameter (@DoorHelper) to check if another parameter I am using(@Door) contains a special value I u开发者_StackOverflow社区se to represent 'global'('9999') and return all Doors in that case.

SELECT 
CASE 
WHEN ('9999'+'-'+ RIGHT(Unknown1,1) in (@Door)) 
THEN (SELECT DISTINCT [Zone]+' - '+CAST([OfficeID] as char(5)) FROM [ADB].[dbo].[ZoneByOffice])
ELSE (@Door)
END AS ZoneID
FROM [ADB].[dbo].[EventLog]

Issue is, returning more than 1 result from a THEN seems to throw errors.

How can I reform this SQL to do what I want it to?


You can use TOP 1

SELECT 
    CASE 
        WHEN ('9999'+'-'+ RIGHT(Unknown1,1) in (@Door)) 
        THEN (SELECT TOP 1 [Zone]+ ' - '+ CAST([OfficeID] as char(5)) FROM [ADB].[dbo].[ZoneByOffice])
        ELSE (@Door)
    END AS ZoneID
FROM [ADB].[dbo].[EventLog]

or you limit the result set with WHERE condition by unique field if any, to guarantee it never returns more than one row.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜