By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,625 Members | 1,497 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,625 IT Pros & Developers. It's quick & easy.

multiple case inside of each other

P: 4
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?
Expand|Select|Wrap|Line Numbers
  1. [Year]= case when isnull(t.status,'') <> 4   
  2. then case when rigth(t.[Year],2)< rigth(t.[tYear],2)
  3. then 
  4. when t.[Year] <= 12 
  5. then '20'+t.[Year] 
  6. else '19'+t.[Year] 
  7. end                     
  8. else t.[tYear]
  9. end
  10. from table
Feb 19 '13 #1
Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,430
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.
Feb 19 '13 #2

P: 4
oops, thanks for you info.
Feb 19 '13 #3

NeoPa
Expert Mod 15k+
P: 31,769
The important point to note here is that you can happily nest CASE statements as long as you follow the syntax correctly.
Feb 19 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.