Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trouble with SQL Case statement

Posted on 2013-05-16
5
Medium Priority
?
660 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

609 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