0

我的案例表达式出现错误。我只想评估一个条件,并返回正确的语句。但是我在“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'
4

2 回答 2

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  

别名ENDCASE表达式中的后面。

于 2013-01-18T21:58:59.497 回答
2

你应该endcase之前as

case 
  when (ProgramAffiliation = magrann.[programAffiliation_AEP/COHesh2010]()) then [AEP] as 
  else [AEP Base] 
end as [AEP1]
// not else [AEP Base]  as 'AEP1' end

更新

于 2013-01-18T21:58:21.333 回答