Solved

Trouble with SQL Case statement

Posted on 2013-05-16
5
594 Views
Last Modified: 2013-05-16
I am trying to write a query in Argos that uses nested case statements, but I keep getting a syntax error.  Can anyone point it out to me?


case lsenrmngt_rec.plan_enr_sess
     when 'FA' then
     case lsenrmngt_rec.enrstat
      when 'READMIT' then
      case
       when lsenrmngt_rec.deg matches 'A*' then
       case lsenrmngt_rec.plan_grad_yr
        when year(current) or year(current+1) then
        readm2a+1
       end
      end
    end readm2a

Open in new window

0
Comment
Question by:Barry62
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 39171879
something like this


SELECT  case lsenrmngt_rec.plan_enr_sess
     when 'FA' then
     case lsenrmngt_rec.enrstat
      when 'READMIT' then
      case when lsenrmngt_rec.deg like '%A*%' then
       case when lsenrmngt_rec.plan_grad_yr= year(GETDATE() ) or lsenrmngt_rec.plan_grad_yr= year(GETDATE()+1) then  readm2a+1 END
     
     end
    end
    End
    readm2a


note, you are missing the else part for all the case statement
0
 
LVL 8

Author Comment

by:Barry62
ID: 39171948
Could you give me an example?
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 39171991
here is the one for the inner most case query

case when lsenrmngt_rec.plan_grad_yr= year(GETDATE() ) or lsenrmngt_rec.plan_grad_yr= year(GETDATE()+1) then  readm2a+1  ELSE  0 END -- not sure what value you need to show in case the condition was not satisfied
0
 
LVL 8

Author Comment

by:Barry62
ID: 39172037
OK, I just realized that I don't need a nested statement because I don't want any 'else' conditions.  I fixed it like this:

case 
     when lsenrmngt_rec.plan_enr_sess = 'FA' and lsenrmngt_rec.enrstat = 'READMIT' and lsenrmngt_rec.deg matches 'A*' and lsenrmngt_rec.plan_grad_yr between year(GETDATE()) and year(GETDATE())+1
        then +1
        else 0
    end readm2a

Open in new window

0
 
LVL 8

Author Closing Comment

by:Barry62
ID: 39172042
I'll give you the points since you got me thinking a different way.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now