Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle SQL:  getting syntax error on sql ... snippet below...

Posted on 2013-06-25
6
Medium Priority
?
464 Views
Last Modified: 2013-06-25
Hi EE,

can you pls help with deciperhing the syntax error below...

am creating a complicated sql...

  it's bec. a student's attribute can reside in either 2 fields

       student_attribute_1
       student_attribute_2

 so am creating a field called calc_attribute to hold the attribute

bec want to create an excel file, to run a Microsoft word mail merge
so want the attribute in one place

i do this using a case when statement....

====

now if the calc_attrib field = MDMP  or MDPH then it's a dual degree medical student student
    and i want to create new fields:
           MD_Matric_Month,
           MD_ Matric_Year
           MD_ADG

i need to derive MD_Matric_Month  from the field: ACADEMIC_PERIOD_MATRICULATED
       and calculate as a named month

term:  201310    10 =  June
            201320   20=   August
            201330   30 =  January

so i am having trouble with the case when statement that are assigning these month values

the case where it's trying to calculate 'August' is giving an error:

"FROM KEYWORD NOT FOUND WHERE EXPECTED"

tx so much for your help, sandra

below is a code snippet:

SELECT  
        ACADEMIC_PERIOD
        ,COLLEGE
        ,PROGRAM          
        ,ID
        ,NAME
        ,STUDENT_ATTRIBUTE_1
        ,STUDENT_ATTRIBUTE_2        
         ,ACADEMIC_PERIOD_MATRICULATED
        ,CASE WHEN   STUDENT_ATTRIBUTE_1 = 'SD' OR STUDENT_ATTRIBUTE_2 = 'SD'  THEN 'SD'
             WHEN   STUDENT_ATTRIBUTE_1 = 'TR' OR STUDENT_ATTRIBUTE_2 = 'TR'  THEN 'TR'
             WHEN   STUDENT_ATTRIBUTE_1 = 'MDPH' OR STUDENT_ATTRIBUTE_2 = 'MDPH'   THEN 'MDPH'
             WHEN   STUDENT_ATTRIBUTE_1 = 'MDMP' OR STUDENT_ATTRIBUTE_2 = 'MDMP'   THEN 'MDMP' END
           AS Calc_Attrib

     
       ,CASE WHEN (CASE              
                        WHEN   STUDENT_ATTRIBUTE_1 = 'MDPH' OR STUDENT_ATTRIBUTE_2 = 'MDPH'   THEN 'MDPH'
                        WHEN   STUDENT_ATTRIBUTE_1 = 'MDMP' OR STUDENT_ATTRIBUTE_2 = 'MDMP'   THEN 'MDMP' END) IN ('MDMP','MDPH')
                                AND SUBSTR(Academic_Period_Matriculated,5,2) = '10' THEN 'June' END    
                               
             WHEN (CASE                            
                        WHEN   STUDENT_ATTRIBUTE_1 = 'MDPH' OR STUDENT_ATTRIBUTE_2 = 'MDPH'   THEN 'MDPH'
                        WHEN   STUDENT_ATTRIBUTE_1 = 'MDMP' OR STUDENT_ATTRIBUTE_2 = 'MDMP'   THEN 'MDMP' END) IN ('MDMP','MDPH')
                                AND SUBSTR(Academic_Period_Matriculated,5,2) = '20' THEN 'August' END                                
                               
                               
           as Calc_DualMatricMonth
0
Comment
Question by:mytfein
  • 3
  • 2
6 Comments
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 1200 total points
ID: 39275160
You have two case statements within a case statement. Each of the inner case statements include an END keyword, but you also have two END keywords for the single outer case statement.
0
 
LVL 78

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 800 total points
ID: 39275166
>>THEN 'June' END

This END kills the outer CASE.
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 1200 total points
ID: 39275180
...
'MDMP'   THEN 'MDMP' END) IN ('MDMP','MDPH') AND SUBSTR(Academic_Period_Matriculated,5,2) = '10' THEN 'June' END => NOT NEEDED
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 32

Assisted Solution

by:awking00
awking00 earned 1200 total points
ID: 39275187
Beat me again :-)
0
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 800 total points
ID: 39275192
When nesting code like this, I always like to line things up.  It's easier to locate mistakes that way:

SELECT  
       CASE WHEN (CASE              
                        WHEN   STUDENT_ATTRIBUTE_1 = 'MDPH' OR STUDENT_ATTRIBUTE_2 = 'MDPH'  
                           THEN 'MDPH'
                        WHEN   STUDENT_ATTRIBUTE_1 = 'MDMP' OR STUDENT_ATTRIBUTE_2 = 'MDMP'
                           THEN 'MDMP'
                  END
                 ) IN ('MDMP','MDPH')
                 AND SUBSTR(Academic_Period_Matriculated,5,2) = '10'
       THEN 'June'
      END
             WHEN (CASE                            
                        WHEN   STUDENT_ATTRIBUTE_1 = 'MDPH' OR STUDENT_ATTRIBUTE_2 = 'MDPH'  
                            THEN 'MDPH'
                        WHEN   STUDENT_ATTRIBUTE_1 = 'MDMP' OR STUDENT_ATTRIBUTE_2 = 'MDMP'  
                            THEN 'MDMP' END
                  ) IN ('MDMP','MDPH')
                  AND SUBSTR(Academic_Period_Matriculated,5,2) = '20'
       THEN 'August'
       END                                
       as Calc_DualMatricMonth
0
 

Author Comment

by:mytfein
ID: 39275341
tx so much everyone,

removed the 'END'

it works now...

tx again, s
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses

916 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