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

volatile table as select..with data - not loading data - response (22) by MBSconnection

$
0
0

Thanks for everyone help.
Here is the Functional Code for Update Query but I still need some Logic Help I am going to put here hoping someone have an guide me in a right direction. I do not have access to writing Store Proc, I do not have DBA access or any Scheduling Tools available.
Update Query.
--------------

UPDATE MY_SANDBOX.objTblTmp
FROM 
    (
        SELECT CAST(RP.REGIS_DATETM AS DATE) AS MyDate,
        	COUNT(DISTINCT RP.REGIS_PRSNA_ID) AS Q1Count
            
        FROM
            iCRM_LOAD.REGIS_PRSNA RP
            
            INNER JOIN iCRM.MKTNG_PGM MP
                            ON RP.MKTNG_PGM_NBR = MP.MKTNG_PGM_NBR
                            
            INNER JOIN iCRM.REGIS_PRSNA_EMAIL_ADDR RPE
                            ON RP.REGIS_PRSNA_ID = RPE.REGIS_PRSNA_ID
                                            AND RP.MKTNG_PGM_NBR = RPE.MKTNG_PGM_NBR
        WHERE
            RP.MKTNG_PGM_NBR IN (115)
            AND RPE.SUBSCRPTN_OPT_IND = 'I'
            AND RP.PRSNA_STATUS_CODE = 'AC'
            
            AND RP.REGIS_DATETM BETWEEN (CURRENT_DATE -7) and CURRENT_DATE          
                           
        GROUP BY CAST (RP.REGIS_DATETM AS DATE)
    )  temp2,
    
    
/*------------------------------------------*/
   
		(SELECT CAST (RP.REGIS_DATETM AS DATE) as MyDate,
    		COUNT (DISTINCT RP.REGIS_PRSNA_ID) as Q2Count
    	
FROM
        iCRM_LOAD.REGIS_PRSNA RP
        
INNER JOIN
        iCRM.MKTNG_PGM MP
        ON RP.MKTNG_PGM_NBR = MP.MKTNG_PGM_NBR
        
INNER JOIN
        iCRM.REGIS_PRSNA_EMAIL_ADDR RPE
        ON RP.REGIS_PRSNA_ID = RPE.REGIS_PRSNA_ID
        AND RP.MKTNG_PGM_NBR = RPE.MKTNG_PGM_NBR

LEFT OUTER JOIN
                ETL_CTRL.LOAD_CONTROL LC
                ON CAST(RP.SYS_SOURCE AS DECIMAL(18,0)) = LC.LOAD_ID
                AND LC.LOAD_TYPE = 'ETL'
                
LEFT OUTER JOIN
                ETL_CTRL.SOURCE_CONTROL SC
                ON LC.SOURCE_ID = SC.SOURCE_ID

WHERE
                RP.MKTNG_PGM_NBR IN (115)
                AND LC.SOURCE_ID IN (1213)
        AND RPE.SUBSCRPTN_OPT_IND = 'I'
        AND RP.PRSNA_STATUS_CODE = 'AC'

AND RP.REGIS_DATETM BETWEEN (CURRENT_DATE -7) and CURRENT_DATE

   GROUP BY CAST (RP.REGIS_DATETM AS DATE)

) temp3,

/*-------------------------------------------------*/

		(SELECT CAST (RP.REGIS_DATETM AS DATE) as MyDate,
			COUNT (DISTINCT RP.REGIS_PRSNA_ID) as  Q3Count
		
FROM
        iCRM_LOAD.REGIS_PRSNA RP
        
INNER JOIN
        iCRM.MKTNG_PGM MP
        ON RP.MKTNG_PGM_NBR = MP.MKTNG_PGM_NBR
        
INNER JOIN
        iCRM.REGIS_PRSNA_EMAIL_ADDR RPE
        ON RP.REGIS_PRSNA_ID = RPE.REGIS_PRSNA_ID
        AND RP.MKTNG_PGM_NBR = RPE.MKTNG_PGM_NBR

LEFT OUTER JOIN
                ETL_CTRL.LOAD_CONTROL LC
                ON CAST(RP.SYS_SOURCE AS DECIMAL(18,0)) = LC.LOAD_ID
                AND LC.LOAD_TYPE = 'ETL'
                
LEFT OUTER JOIN
                ETL_CTRL.SOURCE_CONTROL SC
                ON LC.SOURCE_ID = SC.SOURCE_ID

WHERE
                RP.MKTNG_PGM_NBR IN (115)
                  AND LC.SOURCE_ID IN (1318)
        AND RPE.SUBSCRPTN_OPT_IND = 'I'
        AND RP.PRSNA_STATUS_CODE = 'AC'

AND RP.REGIS_DATETM BETWEEN (CURRENT_DATE -7) and CURRENT_DATE
                
 GROUP BY CAST (RP.REGIS_DATETM AS DATE)
 
 ) as temp4,
 
 
  /* ------------------------------------------*/
  
    (SELECT  CAST(RPE.CNSMR_CHCE_DATETM  AS DATE) as MyDate,
		COUNT (DISTINCT RP.REGIS_PRSNA_ID) as Q4Count
    
FROM
        iCRM_LOAD.REGIS_PRSNA RP
        
INNER JOIN
        iCRM.MKTNG_PGM MP
        ON RP.MKTNG_PGM_NBR = MP.MKTNG_PGM_NBR
        
INNER JOIN
        iCRM.REGIS_PRSNA_EMAIL_ADDR RPE
        ON RP.REGIS_PRSNA_ID = RPE.REGIS_PRSNA_ID
        AND RP.MKTNG_PGM_NBR = RPE.MKTNG_PGM_NBR
        
WHERE
        RP.MKTNG_PGM_NBR IN (115)
        AND RPE.SUBSCRPTN_OPT_IND = 'O'    
AND RPE.CNSMR_CHCE_DATETM BETWEEN (CURRENT_DATE -7) and CURRENT_DATE
        
   GROUP BY CAST ( RPE.CNSMR_CHCE_DATETM AS DATE)
) as temp5,
    
 /*-----------------------------------------------------*/

    
    (SELECT CAST (CA.CNSMR_ACTN_START_DATETM AS DATE) as MyDate,
		COUNT (DISTINCT RP.MATCHD_CNSMR_PRSNA_ID) as Q5Count

FROM
        iCRM_LOAD.REGIS_PRSNA RP
        
INNER JOIN
        iCRM.CNSMR_ACTN CA
		ON RP.REGIS_PRSNA_ID = CA.REGIS_PRSNA_ID
		
WHERE
                CA.MKTNG_PGM_NBR IN (115)
                AND CA.LEGAL_ENT_NBR IN (15)
                AND CA.CNSMR_ACTN_TYPE_CODE IN ('RS')

AND CA.CNSMR_ACTN_START_DATETM  BETWEEN (CURRENT_DATE -7) and CURRENT_DATE
                
        GROUP BY CAST (CA.CNSMR_ACTN_START_DATETM AS DATE)

    ) as temp6,
    
    				
/*----------------------------------------*/

    (SELECT CAST (CA.CNSMR_ACTN_START_DATETM AS DATE) as MyDate,
		COUNT (DISTINCT RP.MATCHD_CNSMR_PRSNA_ID) as Q6Count

FROM
        iCRM_LOAD.REGIS_PRSNA RP
        
INNER JOIN
        iCRM.CNSMR_ACTN CA
		ON RP.REGIS_PRSNA_ID = CA.REGIS_PRSNA_ID
		
WHERE
                CA.MKTNG_PGM_NBR IN (115)
                AND CA.LEGAL_ENT_NBR IN (15)
                AND CA.CNSMR_ACTN_TYPE_CODE IN ('RC')

AND CA.CNSMR_ACTN_START_DATETM  BETWEEN (CURRENT_DATE -7) and CURRENT_DATE

                GROUP BY CAST (CA.CNSMR_ACTN_START_DATETM AS DATE)

 as temp7,


/*---------------------------------------------------------*/
    
    (SELECT CAST (CA.CNSMR_ACTN_START_DATETM AS DATE) as MyDate,
		COUNT (DISTINCT RP.MATCHD_CNSMR_PRSNA_ID) as Q7Count

FROM
        iCRM_LOAD.REGIS_PRSNA RP
INNER JOIN
        iCRM.CNSMR_ACTN CA
		ON RP.REGIS_PRSNA_ID = CA.REGIS_PRSNA_ID
WHERE
                CA.MKTNG_PGM_NBR IN (115)
                AND CA.LEGAL_ENT_NBR IN (15)
                AND CA.CNSMR_ACTN_TYPE_CODE IN ('CR')


AND CA.CNSMR_ACTN_START_DATETM  BETWEEN (CURRENT_DATE -7) and CURRENT_DATE

            GROUP BY CAST (CA.CNSMR_ACTN_START_DATETM AS DATE)

    
    
    ) as temp8
                
                
SET Q1Count = coalesce(temp2.Q1Count,0),
Q2Count = coalesce(temp3.Q2Count,0),
Q3Count = coalesce(temp4.Q3Count,0),
Q4Count = coalesce(temp5.Q4Count,0),
Q5Count = coalesce(temp6.Q5Count,0),
Q6Count = coalesce(temp7.Q6Count,0),
Q7Count = coalesce(temp8.Q7Count,0)
WHERE objTblTmp.MyDate = temp2.MyDate
and  objTblTmp.MyDate = temp3.MyDate
and  objTblTmp.MyDate = temp4.MyDate
and objTblTmp.MyDate = temp5.MyDate 
and objTblTmp.MyDate = temp6.MyDate 
and objTblTmp.MyDate = temp7.MyDate 
and objTblTmp.MyDate = temp8.MyDate;







 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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