0

ケース式でエラーが発生します。1つの条件を評価して、適切なステートメントを返したいだけです。しかし、「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が間違っています。列名が一重引用符で囲まれ、エイリアスが2か所にあります(どちらも間違っています)。

 , 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

あなたは前に持っている必要が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

更新しました

于 2013-01-18T21:58:21.333 に答える