Proc SQL创建表语句不起作用但没有错误?

时间:2015-11-24 11:26:23

标签: sql sas teradata

我在SAS E.G上有一系列创建表语句。它们孤立地工作没有问题但是当我一起运行它们时,只有第一个表创建。日志中没有错误,也没有指示它甚至试图运行第二组表。

代码必须作为更大项目的一部分一起运行。任何帮助,将不胜感激! (我已经编辑了部分内容,因为它很长,并评论了问题似乎发生的部分。)

EXECUTE( CREATE MULTISET TABLE TEMP_BAG_CAR_BASET
(
 REGISTRATION_ID           INTEGER
,SOURCE_SYSTEM_CD          BYTEINT
,BILLING_BASE              VARCHAR(20)
,INSIGHT_BILLING_BASE      VARCHAR(20)
,ENTERPRISE_IND            BYTEINT
,BILLING_ACCOUNT_NO        INTEGER

) PRIMARY INDEX (REGISTRATION_ID)
) BY TERADATA;


EXECUTE (INSERT INTO TEMP_BAG_CAR_BASET
SELECT 
      A.REGISTRATION_ID
      ,A.SOURCE_SYSTEM_CD
      ,A.BILLING_BASE
      ,A.INSIGHT_BILLING_BASE
      ,A.ENTERPRISE_IND
      ,CASE WHEN A.BILLING_ACCOUNT_NO > 0 THEN A.BILLING_ACCOUNT_NO
            WHEN Z.BILLING_ACCOUNT_NO > 0 AND A.SOURCE_SYSTEM_CD = 2 THEN Z.BILLING_ACCOUNT_NO
            WHEN V.BAN >0 AND A.SOURCE_SYSTEM_CD = 0 THEN V.BAN
             ELSE NULL END

FROM [SOURCE 1] AS A
   LEFT JOIN [SOURCE 2] AS V ON A.REGISTRATION_ID = B.REGISTRATION_ID 
          AND A.DISCONNECTION_DT <= V.DISCONN_DATE AND A.DISCONNECTION_DT > V.CONN_DATE
          AND V.CONN_DATE <= %SYSEVALF(%SYSFUNC(PUTN(&ENDDATE, YYMMDDN8.))-19000000)
INNER JOIN (SELECT REGISTRATION_ID
                  ,BILLING_ACCOUNT_TYP
            FROM [SOURCE 3]
                 WHERE %SYSEVALF(%SYSFUNC(PUTN(&ENDDATE, YYMMDDN8.))-19000000) BETWEEN EFFECTIVE_DT AND EXPIRY_DT
                 AND REF_RULE_BASE_IND = 'Y') AS B
ON A.REGISTRATION_ID = B.REGISTRATION_ID
LEFT JOIN (SELECT REGISTRATION_ID
                  ,REGISTERED_SOURCE_SYSTEM_CD
                  ,BILLING_ACCOUNT_CD AS BILLING_ACCOUNT_NO
                  ,CORPORATE_ID
            FROM [SOURCE 3]
                 WHERE (CAST(&MTH0 AS DATE) +1) BETWEEN EFFECTIVE_DT AND EXPIRY_DT
                 AND REF_RULE_BASE_IND = 'Y') AS Z
ON A.REGISTRATION_ID = Z.REGISTRATION_ID

LEFT JOIN [SOURCE 4]E
    ON A.PORTED_IN_FROM = E.NETWORK_PROVIDER_ID
   AND E.EXPIRY_DT = 16001231
LEFT JOIN [SOURCE 5] AS F
    ON F.EXPIRY_DT = 16001231

      WHERE     A.ENTERPRISE_IND = 0 
            AND A.REGISTERED_BASE_IND = 1 
            AND A.REGISTRATION_TYP = 1
            AND SUMMARY_DT = %SYSEVALF(%SYSFUNC(PUTN(&ENDDATE, YYMMDDN8.))-19000000)
)
BY TERADATA;

EXECUTE
(
COLLECT STATISTICS TEMP_BAG_CAR_BASET INDEX(REGISTRATION_ID)
)
BY TERADATA;

/*At this point the code does not create any of the following tables but no errors occur */

EXECUTE( CREATE MULTISET TABLE TEMP_BAG_CAR_BASE
(
REGISTRATION_ID           INTEGER
,SOURCE_SYSTEM_CD          BYTEINT
,BILLING_BASE              VARCHAR(20)
,INSIGHT_BILLING_BASE      VARCHAR(20)
,ENTERPRISE_IND            BYTEINT
,BILLING_ACCOUNT_NO        INTEGER
) PRIMARY INDEX (REGISTRATION_ID)
) BY TERADATA;


  EXECUTE(INSERT INTO TEMP_BAG_CAR_BASE
SELECT 
      A.REGISTRATION_ID
      ,SOURCE_SYSTEM_CD
      ,BILLING_BASE
      ,INSIGHT_BILLING_BASE
      ,ENTERPRISE_IND
      ,BILLING_ACCOUNT_NO

FROM TEMP_BAG_CAR_BASET AS A
INNER JOIN (SELECT REGISTRATION_ID
                   ,MAX(DISCONN_DATE    ) AS DISCONN_DATE
            FROM TEMP_BAG_CAR_BASET
            GROUP BY 1) AS B
ON A.REGISTRATION_ID = B.REGISTRATION_ID
AND A.DISCONN_DATE     = B.DISCONN_DATE
)
BY TERADATA;

2 个答案:

答案 0 :(得分:1)

您可能需要插入COMMIT语句。

execute (COMMIT) by teradata;

答案 1 :(得分:0)

默认情况下,SAS \​​ ACCESS for Teradata接口使用ANSI事务语义。如果未在MODE语句中指定CONNECT TO TERADATA()参数,则会话语义可能是ANSI。

正如Tom上面所建议的那样,使用EXECUTE(COMMIT) BY TERADATA;或将MODE=TERADATA添加到PROC SQL中的CONNECT TO TERADATA()语句中。