2013-10-26 3 views
2

안녕하세요, 입력했거나 볼 때 결정할 코드를 확인하는 다음 쿼리가 있습니다. 내가 그것을 제공이 쿼리를 실행하려고하면select 쿼리에서 여러 case 문 사용

 declare @timestamp datetime; 
     select 
      case @timestamp 
      when a.updatedDate =1760 then 'Entered on' +a.updatedDate 
      when a.updatedDate=1710 then 'Viewed on' +a.updatedDate 
      else 'Last Updated on'+ a.updatedDate 
      end 
     from t_mainTable a 
     where [email protected]; 

나 일부 syntex 오류가 때 라인이

Msg 102, Level 15, State 1, Procedure p_xxxx, line 40 
Incorrect syntax near '='. 

오류가 발생했습니다. 날이 감사를 해결하는 방법을 알려 주시기 바랍니다

+4

'@ 타임 스탬프 '를 제거하십시오. –

답변

18

경우 문을 작성하는 방법은 두 가지가 있습니다, 당신은 동등한 두

case a.updatedDate 
    when 1760 then 'Entered on' + a.updatedDate 
    when 1710 then 'Viewed on' + a.updatedDate 
    else 'Last Updated on' + a.updateDate 
end 

또는

case 
    when a.updatedDate = 1760 then 'Entered on' + a.updatedDate 
    when a.updatedDate = 1710 then 'Viewed on' + a.updatedDate 
    else 'Last Updated on' + a.updateDate 
end 

의 조합을 사용하는 것 . 날짜 유형을 다른 varchar에 추가하려면 varchars로 변환해야 할 수도 있기 때문에 작동하지 않을 수 있습니다.