我的case表达式出现错误。我只想计算一个条件,然后返回正确的语句。但是我一直在"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'发布于 2013-01-19 05:58:59
您的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 别名位于CASE表达式中的END之后。
发布于 2013-01-19 05:58:21
在as之前,case中应该有end
case
when (ProgramAffiliation = magrann.[programAffiliation_AEP/COHesh2010]()) then [AEP] as
else [AEP Base]
end as [AEP1]
// not else [AEP Base] as 'AEP1' end已更新
https://stackoverflow.com/questions/14408294
复制相似问题