Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
865 B
1
Indexable
Never
CREATE PROCEDURE DWHCDE.PI_AR59C (
    IN @I_BSNDT DATE
)
LANGUAGE SQL
SPECIFIC DWHCDE.PI_AR59C
NOT DETERMINISTIC
MODIFIES SQL DATA
BEGIN
    -- Check if PRXMINVC.INVOICEUNIQID = 0
    DECLARE @COUNT INT;
    SET @COUNT = (SELECT COUNT(*) FROM DWHINPSTG.PRXMINVC WHERE PRXMINVC.INVOICEUNIQID <> 0);
    
    IF @COUNT = 1 THEN
        -- Copy data from DWHINPSTG.AR59C to DWHINPSTG.AR59P
        INSERT INTO DWHINPSTG.AR59P
        SELECT * FROM DWHINPSTG.AR59C;
        
        -- Delete all records from DWHINPSTG.AR59C
        DELETE FROM DWHINPSTG.AR59C;
    ELSE
        -- Normal code execution 
        INSERT INTO DWHINPSTG.AR59C (ARCD, IPCD, INVCPDCD, INVCPDDSC, VLDLCTVFLG, VLDDT, ISFNFLG, FNNCDT, ACTOVRDFLG, ISSDT, DDT, NOTSTLDFLG, PMTDT, INVCCCYCD, FNNCPRD, SPPLRCD, SPPLRIPCD, SPPLRNM, SPPLRIBAN, BYRACCCD, SPBYRACCCD)