2017-04-04 58 views
0

的錯誤如下:創建DB2存儲過程Error..can人提供洞察

H1WICTDD.WICQ083A:44:非法符號 「」。這可能是 法律一些符號是:+ - (TRIM XMLSERIALIZE CAST XMLCAST CASE CURRENT_DATE SQLCODE = -104,SQLSTATE = 42601,DRIVER = 3.62.80

的SQL(我沒有得到任何語法警告之前嘗試部署):

CREATE PROCEDURE H1WICTDD.WICQ083a(IN parmCollection VARCHAR(8), IN parmAgencyID CHAR(3), IN parmSQLCODE INT) 
    VERSION V1 
    ISOLATION LEVEL CS 
    RESULT SETS 1 
    LANGUAGE SQL 
    QUALIFIER H1xxx 

P1:BEGIN 

DECLARE strAgencyID VARCHAR(3); 
DECLARE dtDATE DATE; 
DECLARE strServer VARCHAR(10); 
DECLARE strUser VARCHAR(8); 
DECLARE strLowAgencyID CHAR(3); 
DECLARE c_result CURSOR WITH RETURN FOR RES_SET; 


SET dtDate=(CURRENT DATE - 13 MONTHS); 
SET strServer=CURRENT SERVER; 
SET strUser=USER; 

--SELECT CURRENT SERVER INTO strServer FROM SYSIBM.SYSDUMMY1; 
--SELECT CURRENT SESSION_USER INTO strUser FROM SYSIBM.SYSDUMMY1; 


IF strServer = 'HWDCH1xxx' THEN         
    SET strLowAgencyID ='100'; 
ELSE 
    SET strLowAgencyID ='101'; 
END IF;       


SELECT GAGENCYID INTO strAgencyID          
FROM VINFWICIDUSER          
WHERE GUSERID = strUser 
WITH UR;            

--If strAgencyID of the USER equals the passed in parmAgency ID 
--or strAgencyID has astriks (*) then the user has access to statewide 
--Reports. So test taht first. If passes that test, then see if they 
--want state or agency only 

IF strAgencyID=parmAgencyID OR strAgencyID Like '*%' THEN 
    IF parmAgencyID=’ALL’ THEN 
--STATEWIDE 
    SELECT             
     A.GAGENCYID,           
     B.GAGENCYNAME,           
     A.GPARTICIPMONTH,          
     C.GCASELOADCNT,           
     A.GPARTICIPATION,          
     (C.GCASELOADCNT - A.GPARTICIPATION) AS GCLESSP,   
     COALESCE(SUM(D.GCNTTOTAL),0) AS GUNISSUEDCNT   
     FROM              
     VINFPARTICPSUMM A          
     INNER JOIN VINFAGENCY B         
      ON B.GAGENCYID = A.GAGENCYID     
     INNER JOIN VINFCASELOAD C        
      ON C.GAGENCYID = A.GAGENCYID     
     LEFT OUTER JOIN VINFUNISSUEDRX D      
      ON D.GAGENCYID = A.GAGENCYID     
      AND CONCAT(SUBSTR(CHAR(A.GPARTICIPMONTH,ISO),1,4),  
       SUBSTR(CHAR(A.GPARTICIPMONTH,ISO),6,2))  
      = D.GRXMONTHYEAR         
     WHERE             
     A.GPARTICIPMONTH >= dtDATE      
     AND A.GAGENCYID BETWEEN strLowAgencyID AND '399' 
     AND C.GEFFECTIVEDATE =         
      (SELECT MAX(E.GEFFECTIVEDATE)      
      FROM VINFCASELOAD E         
      WHERE E.GAGENCYID  = A.GAGENCYID    
      AND E.GEFFECTIVEDATE <= A.GPARTICIPMONTH)   
     GROUP BY A.GAGENCYID,         
     B.GAGENCYNAME,           
     A.GPARTICIPMONTH,          
     A.GPARTICIPATION,          
     C.GCASELOADCNT 
     WITH UR;                   

     ELSE 
--AGENCY 
    SELECT             
     A.GAGENCYID,           
     B.GAGENCYNAME,           
     A.GPARTICIPMONTH,          
     C.GCASELOADCNT,          
     A.GPARTICIPATION,          
     (C.GCASELOADCNT - A.GPARTICIPATION) AS GCLESSP,   
     COALESCE(SUM(D.GCNTTOTAL),0) AS GUNISSUEDCNT   
     FROM              
     VINFPARTICPSUMM A          
     INNER JOIN VINFAGENCY B        
      ON B.GAGENCYID = A.GAGENCYID     
     INNER JOIN VINFCASELOAD C        
      ON C.GAGENCYID = A.GAGENCYID     
     LEFT OUTER JOIN VINFUNISSUEDRX D      
      ON D.GAGENCYID = A.GAGENCYID     
      AND CONCAT(SUBSTR(CHAR(A.GPARTICIPMONTH,ISO),1,4),   
       SUBSTR(CHAR(A.GPARTICIPMONTH,ISO),6,2))   
      = D.GRXMONTHYEAR         
     WHERE              
     A.GPARTICIPMONTH >= dtDATE      
     AND A.GAGENCYID = parmAgencyID      
     AND C.GEFFECTIVEDATE =         
      (SELECT MAX(E.GEFFECTIVEDATE)       
      FROM VINFCASELOAD E         
      WHERE E.GAGENCYID = A.GAGENCYID      
      AND E.GEFFECTIVEDATE <= A.GPARTICIPMONTH)   
     GROUP BY A.GAGENCYID,         
     B.GAGENCYNAME,           
     A.GPARTICIPMONTH,          
     A.GPARTICIPATION,          
     C.GCASELOADCNT           
WITH UR;         

    END IF; 

END IF; 
OPEN c_result; 
--============================================================= 
--Handle Errors and Log them 
--============================================================== 

     --EXEC Stored Proc WICQ00R (STORPROC_NAME, RETURN_CODE, MISC, strUser, CURRENT DATETIME) 

END P1 
+0

在一個複合語句中,你只能'SELECT'' INTO'(或聲明一個遊標)。 – mustaccio

+0

這似乎是這種情況。謝謝 – KML

+0

編輯顯示錯誤。 – ManishChristian

回答

0

該錯誤消息表示線44,這是

IF parmAgencyID=’ALL’ THEN 

我猜smartquotes不意

0

謝謝eveyone。它出現在DB2中,我不能有條件邏輯規定要使用的SELECT語句。我必須在每個SELECT語句之前聲明一個CURSOR,然後將條件邏輯放在底部並打開相應的CuRSOR。我把下面的代碼的程序的底部:

SET DTDATE=(CURRENT DATE - 13 MONTHS); 
SET STRSERVER=CURRENT SERVER; 
SET STRUSER=USER; 

SELECT GAGENCYID INTO STRAGENCYID FROM VINFWICIDUSER          
WHERE GUSERID = STRUSER; 

IF STRSERVER = 'HWDCH1TD' THEN         
    SET STRLOWAGENCYID ='100'; 
ELSE 
    SET STRLOWAGENCYID ='101'; 
END IF; 

IF STRAGENCYID = PARMAGENCYID OR STRAGENCYID LIKE '*%' THEN 
    IF PARMAGENCYID = 'ALL' THEN 
     OPEN C_STATE; --The DECLARED CURSOR in first SELECT 
    ELSE 
     OPEN C_AGENCY; --The DECLARED CURSOR in the second SELECT 
    END IF; 
END IF; 
--============================================================= 
--Handle Errors and Log them 
--============================================================== 
     --EXEC Stored Proc WICQ00R (STORPROC_NAME, RETURN_CODE, MISC, strUser, CURRENT DATETIME) 
END P1 

我們擁有一個具有使用遊標所以不知道在那裏我將前往什麼麻煩報告制度......

感謝您的答覆。