Solved

Trouble with SQL Case statement

Posted on 2013-05-16
5
618 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 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

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
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…

733 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