Link to home
Start Free TrialLog in
Avatar of Barry62
Barry62Flag for United States of America

asked on

Trouble with SQL Case statement

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

Avatar of Aneesh
Aneesh
Flag of Canada image

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
Avatar of Barry62

ASKER

Could you give me an example?
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Barry62

ASKER

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

Avatar of Barry62

ASKER

I'll give you the points since you got me thinking a different way.