Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

IF/THEN Statement not working (Stored Procedure) - forum topic by staples728

$
0
0

Hello,
I have a dynamic stored procedure with an if statement setting a stmt to include in my insert statement. I will only share a portion of the code, enough to get the idea across.  The procedure compiles correctly, but when I validate my if statement this error is returned:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL  server version for the right syntax to use near 'IF (SELECTED_PROJECT_LOBSELECTION = 'Copy the Whole Project') THEN
      SET lob' at line 1:

My If statement is as follows: 

DECLARE CURSOR_C CURSOR WITH RETURN FOR PREPSTMT;
 

     IF (SELECTED_PROJECT_LOBSELECTION = 'Copy the Whole Project') THEN
   SET lobInsertStmt = ' AND p.PROJECTION_PROJECT_NME = ' || SELECTED_PROJECT_NAME
             || ' AND p.PROJECTION_PROJ_CATG_NME = ' || SELECTED_PROJECT_CATG
             || ' AND p.FINANCIAL_PROJECTION_YEAR_NUM = ' || CAST(SELECTED_PROJECT_YEAR AS int)
             || ' AND g.MODEL_GROUP_SNAPSHOT_TSP = ' || SELECTED_SNAPSHOT_TIMESTAMP; 
      
            
 ELSEIF SELECTED_PROJECT_LOBSELECTION = 'Copy All NB Models Only' THEN
      SET lobInsertStmt = ' AND p.PROJECTION_PROJECT_NME = ' || SELECTED_PROJECT_NAME
             || ' AND p.PROJECTION_PROJ_CATG_NME = ' || SELECTED_PROJECT_CATG
             || ' AND p.FINANCIAL_PROJECTION_YEAR_NUM = ' || CAST(SELECTED_PROJECT_YEAR AS int)
             || ' AND g.MODEL_GROUP_SNAPSHOT_TSP = ' || SELECTED_SNAPSHOT_TIMESTAMP
             || ' AND m.PROJECTION_MODEL_CATEGORY_NME IN ('|| SELECTED_PROJECT_TYPE || ')';  
....

 END IF;
     
    PREPARE PREPSTMT FROM lobInsertStmt;

.....

OPEN CURSOR_C; 

 
Any suggestions are much appreciated. Thanks!
 

Forums: 

Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>