[英]SQL - CASE STATEMENT - Count statement and case function
我正在尝试在count语句中编写函数when
的case
,但出现错误4145。
select @CountResult = count(*) from ViewDefinition where DefinitionID = @ObjektID and
(case
when IsGepa=0 and Gepa is not null then @CountResult
when NotGepa=0 and GepaListeID is not null then @CountResult
end )
select @CountResult
尝试这个:
select @CountResult = SUM
(
CASE when (IsGepa=0 and Gepa is not null ) OR (NotGepa=0 and GepaListeID is not null) THEN 1 ELSE 0 END
)
from ViewDefinition
where DefinitionID = @ObjektID
您的CASE条件需要输入以下位置:
select @CountResult = count(*)
from ViewDefinition
where DefinitionID = @ObjektID and
((IsGepa=0 and Gepa is not null) or
(NotGepa=0 and GepaListeID is not null)
)
select @CountResult
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.