我正在尝试在count语句中编写一个case
when
函数,但出现错误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
答案 0 :(得分:0)
尝试一下:
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
答案 1 :(得分:0)
您的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