?
Solved

Trouble with SQL Case statement

Posted on 2013-05-16
5
Medium Priority
?
668 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 using thread_statistics can cause high memory usage.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

807 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