multiple case inside of each other

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sqlfzk
    New Member
    • Feb 2013
    • 4

    multiple case inside of each other

    Hi, how I can create a column with case when I need another case in "then"; here is my problem: fyi, tyear is 4 diget and year is 2 diget; what I'm doing wrong?
    Code:
    [Year]= case when isnull(t.status,'') <> 4   
    then case when rigth(t.[Year],2)< rigth(t.[tYear],2)
    then 
    when t.[Year] <= 12 
    then '20'+t.[Year] 
    else '19'+t.[Year] 
    end 					
    else t.[tYear]
    end
    from table
    Last edited by Rabbit; Feb 19 '13, 09:51 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Line 2, you spelled right incorrectly.

    Line 3, you need an expression after your then, you can't go directly into another when regardless of whether or not you're using nested cases.

    Comment

    • sqlfzk
      New Member
      • Feb 2013
      • 4

      #3
      oops, thanks for you info.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        The important point to note here is that you can happily nest CASE statements as long as you follow the syntax correctly.

        Comment

        Working...