我想帶回縣名和縣名。我該如何解決這個問題?sql case語句帶回多個值
DECLARE @test int = 0;
select
CASE (@test)
when 0 then (SELECT co.Id, co.Description
FROM Dictionary.Counties as co
INNER JOIN CountyCollaboration as cc on cc.CountyId = co.Id
WHERE cc.CollaborationId = (SELECT cc1.CollaborationId from CountyCollaboration as cc1
WHERE cc1.CountyId = 34))
END
我得到的錯誤only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
如果我註釋掉co.Description
所以我只帶回co.Id
,我得到一個不同的錯誤:subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <=, >, >=, or when the subquery is used as as expression.
如果你可以解釋你爲什麼要這樣做,可能會有一個簡單的解決方法,避免任何'CASE'或'IF'語句。 – bendataclear