我想带回县名和县名。我该如何解决这个问题?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