我的案例表达式出错了。我只想评估一个条件,并返回正确的语句。但我一直在“as”附近收到语法错误。
这就是我所拥有的:
left outer join (
SELECT wbs1, wbs2, wbs3
, case
when (ProgramAffiliation = magrann.[programAffiliation_AEP/COHesh2010]())
then '[AEP] as ''AEP1'''
else [AEP Base] as 'AEP1'
end
, [AEP:Non-Compliant Mechanical Ventilation] as 'AEP2'
, [AEP - Non Energy Star AC ($90 deduction)] as 'AEP3'
, [AEP: Bonus] as 'AEP4'
答案 0 :(得分:4)
您的CASE
语法错误。你有一个用单引号括起来的列名,你有两个地方的别名(都错了):
, case
when (ProgramAffiliation = magrann.[programAffiliation_AEP/COHesh2010]())
then '[AEP] as ''AEP1''' -- <-- don't put the column in single quotes and no alias here
else [AEP Base] as 'AEP1' -- < don't put the alias here
end -- < the alias goes here
所以你的CASE
应该是:
, case
when (ProgramAffiliation = magrann.[programAffiliation_AEP/COHesh2010]())
then [AEP]
else [AEP Base]
end as AEP1
别名位于END
表达式中的CASE
之后。
答案 1 :(得分:2)
end
之前case
中应该as
:
case
when (ProgramAffiliation = magrann.[programAffiliation_AEP/COHesh2010]()) then [AEP] as
else [AEP Base]
end as [AEP1]
// not else [AEP Base] as 'AEP1' end
更新