选择失败。 3706:语法错误:预期在'('和'current_date'关键字之间

时间:2018-12-06 17:02:48

标签: sql teradata

我正在使用Teradata和以下查询从我们的数据库中提取一些数据,并在运行它时出现以下错误:

SELECT Failed. 3706: Syntax error: expected something between '(' and the 'current_date' keyword

我不知道为什么会出现此错误,有人可以帮我吗?我已经在先前的请求中使用了current_date,并且之前没有出错。在围绕current_day的代码中,我似乎也找不到任何特别的错误。

谢谢!

select
  "T0"."C0" / (NULLIF("T0"."C1", 0)) "C___Reserved",
  "T0"."C2" "Cust_Sold_To_Cd",
  "T0"."C3" "SO_Doc_Hdr_Nbr",
  "T0"."C4" "Div_Cd",
  "T0"."C5" "Prod_Cd",
  "T0"."C6" "CRD_Dt_Bus_Mo_Yr__YYYYMM_",
  "T0"."C7" "CRD_Dt",
  "T0"."C0" "Rsrvd_On_Hand_Inv_Qty",
  "T0"."C1" "Rmaing_To_Ship_Rptg_Cnfrmd_Qty",
  "T0"."C8" "CCD_Dt_Bus_Mo_Yr__YYYYMM_",
  "T0"."C9" "Distrib_Mthd_Cd",
  "T0"."C10" "SO_Type_Cd",
  "T0"."C11" "Gbl_Cat_Sum_Desc",
  "T0"."C12" "Cust_Sold_To_Nm",
  "T0"."C13" "Cust_Ship_To_Cd",
  "T0"."C14" "Cust_Ship_To_Nm",
  "T0"."C15" "Plnt_Id_Cd",
  "T0"."C16" "SO_Ln_Itm_Nbr",
  "T0"."C17" "Styl_Nm",
  "T0"."C18" "Mgmt_Rep_Nm"
from
  (
    select
      sum(
        zeroifnull("Cvrg_SO_SchedLn_Trnspd"."RsrvdToOnHandInvQty")
      ) "C0",
      sum(
        zeroifnull(
          "Cvrg_SO_SchedLn_Trnspd"."RmaingRptgCnfrmdToDlvrQty"
        )
      ) "C1",
      (
        case
          when 'C2' in ('1') then "so_core_v"."SoldToNbr"
        end
      ) "C2",
      "so_core_v"."SO_HdrNbr" "C3",
      "so_core_v"."DivCd" "C4",
      (
        case
          "ProdtGPI"."ProdtCd"
          when '*UNK*' then ''
          else "ProdtGPI"."ProdtCd"
        end
      ) "C5",
      "Cal_BusCal_CRD"."MonthPerCd" "C6",
      (
        case
          "so_core_v"."CRD"
          when cast('0001-01-01' as date) then NULL
          else "so_core_v"."CRD"
        end
      ) "C7",
      "Cal_BusCal_CCD"."MonthPerCd" "C8",
      (
        case
          when 'C9' in ('1') then (
            case
              "so_core_v"."DistribMthdCd"
              when '*UNK*' then ''
              else "so_core_v"."DistribMthdCd"
            end
          )
        end
      ) "C9",
      "SO_DocType"."SO_DocTypeCd" "C10",
      (
        case
          when 'C12' in ('1') then "GlblCatSum"."GlblCatSumDesc"
        end
      ) "C11",
      (
        case
          when 'C3' in ('1') then (
            coalesce(
              "Cust_l_Sold_To"."CustDesc",
              "Cust_Sold_To"."CustNm"
            )
          )
        end
      ) "C12",
      (
        case
          when 'C4' in ('1') then "so_core_v"."ShipToNbr"
        end
      ) "C13",
      (
        case
          when 'C5' in ('1') then (
            coalesce(
              "Cust_l_Ship_To"."CustDesc",
              "Cust_Ship_to_so_core_"."CustNm"
            )
          )
        end
      ) "C14",
      (
        case
          when 'E9' in ('1') then "Plnt"."PlntIdCd"
        end
      ) "C15",
      "so_core_v"."SO_ItmNbr" "C16",
      (
        coalesce(
          (
            NULLIF("ProdtLocizedTransl"."LocizedProdtNm", ' ')
          ),
          "ProdtGPI"."ProdtLglLongNm"
        )
      ) "C17",
      (
        case
          when 'DC' in ('1') then "SlsRep_so_core_"."SlsRepNm"
        end
      ) "C18"
    from
      (
        (
          (
            (
              (
                (
                  (
                    (
                      (
                        (
                          (
                            (
                              (
                                (
                                  "EIS"."Cal_BusCal" "Cal_BusCal_CCD"
                                  INNER JOIN "EIS"."SO_Core_v" "so_core_v" on "Cal_BusCal_CCD"."CalDt" = "so_core_v"."CCD"
                                  and "Cal_BusCal_CCD"."CalCd" = "so_core_v"."BusCalCd"
                                )
                                INNER JOIN "EIS"."Cal_BusCal" "Cal_BusCal_CRD" on "Cal_BusCal_CRD"."CalDt" = "so_core_v"."CRD"
                                and "Cal_BusCal_CRD"."CalCd" = "so_core_v"."BusCalCd"
                              )
                              INNER JOIN "EIS"."Cust" "Cust_Ship_to_so_core_" on "Cust_Ship_to_so_core_"."CustCd" = "so_core_v"."ShipToNbr"
                            )
                            INNER JOIN "EIS"."Cust" "Cust_Sold_To" on "Cust_Sold_To"."CustCd" = "so_core_v"."SoldToNbr"
                          )
                          INNER JOIN "EIS"."Plnt" "Plnt" on "Plnt"."PlntIdCd" = "so_core_v"."PlntCd"
                        )
                        INNER JOIN "EIS"."SO_DocType" "SO_DocType" on "SO_DocType"."SO_DocTypeCd" = "so_core_v"."SO_DocTypeCd"
                      )
                      INNER JOIN "EIS"."ProdtGPI" "ProdtGPI" on "ProdtGPI"."ProdtCd" = "so_core_v"."ProdtCd"
                    )
                    INNER JOIN "EIS"."GlblCatCoreFcs" "GlblCatCoreFcs" on "GlblCatCoreFcs"."GlblCatCoreFcsCd" = "ProdtGPI"."GlblCatCoreFcsCd"
                  )
                  INNER JOIN "EIS"."GlblCatSum" "GlblCatSum" on "GlblCatSum"."GlblCatSumCd" = "GlblCatCoreFcs"."GlblCatSumCd"
                )
                LEFT OUTER JOIN "EIS"."Cust_l" "Cust_l_Ship_To" on "Cust_Ship_to_so_core_"."CustCd" = "Cust_l_Ship_To"."CustCd"
                and 'F' = "Cust_l_Ship_To"."LangCd"
              )
              LEFT OUTER JOIN "EIS"."Cust_l" "Cust_l_Sold_To" on "Cust_Sold_To"."CustCd" = "Cust_l_Sold_To"."CustCd"
              and 'F' = "Cust_l_Sold_To"."LangCd"
            )
            LEFT OUTER JOIN "EIS"."Cvrg_SO_SchedLn_Trnspd" "Cvrg_SO_SchedLn_Trnspd" on "so_core_v"."SO_HdrCrtDt" = "Cvrg_SO_SchedLn_Trnspd"."SO_HdrCrtDt"
            and "so_core_v"."SO_ItmNbr" = "Cvrg_SO_SchedLn_Trnspd"."SO_ItmNbr"
            and "so_core_v"."SO_SchedNbr" = "Cvrg_SO_SchedLn_Trnspd"."SO_SchedNbr"
            and "so_core_v"."CCD" = "Cvrg_SO_SchedLn_Trnspd"."CCD"
            and "so_core_v"."DivCd" = "Cvrg_SO_SchedLn_Trnspd"."DivCd"
            and "so_core_v"."SlsOrgCd" = "Cvrg_SO_SchedLn_Trnspd"."SlsOrgCd"
            and "so_core_v"."SuperGeoID" = "Cvrg_SO_SchedLn_Trnspd"."SuperGeoID"
            and "so_core_v"."SO_HdrNbr" = "Cvrg_SO_SchedLn_Trnspd"."SO_HdrNbr"
            and "so_core_v"."OrigPhysSrcSysSK" = "Cvrg_SO_SchedLn_Trnspd"."OrigPhysSrcSysSK"
          )
          LEFT OUTER JOIN "EIS"."SO_Unshpble" "SO_Unshpble" on "so_core_v"."SO_HdrNbr" = "SO_Unshpble"."SO_HdrNbr"
          and "so_core_v"."SO_HdrCrtDt" = "SO_Unshpble"."SO_HdrCrtDt"
          and "so_core_v"."SO_ItmNbr" = "SO_Unshpble"."SO_ItmNbr"
          and "so_core_v"."SO_SchedNbr" = "SO_Unshpble"."SO_SchedNbr"
          and "so_core_v"."SuperGeoID" = "SO_Unshpble"."SuperGeoId"
          and "so_core_v"."CCD" = "SO_Unshpble"."CCD"
          and "so_core_v"."DivCd" = "SO_Unshpble"."DivCd"
          and "so_core_v"."SlsOrgCd" = "SO_Unshpble"."SlsOrgCd"
          and "so_core_v"."OrigPhysSrcSysSK" = "SO_Unshpble"."OrigPhysSrcSysSK"
        )
        LEFT OUTER JOIN "EIS"."SlsRep" "SlsRep_so_core_" on "so_core_v"."OrigPhysSrcSysSK" = "SlsRep_so_core_"."OrigPhysSrcSysSK"
        and "so_core_v"."MgmtRepNbr" = "SlsRep_so_core_"."SlsRepNbr"
        and 'Y' = "SlsRep_so_core_"."ActvInd"
      )
      LEFT OUTER JOIN "EIS"."ProdtLocizedTransl" "ProdtLocizedTransl" on "ProdtGPI"."ProdtCd" = "ProdtLocizedTransl"."ProdtCd"
      and upper ('fr') = "ProdtLocizedTransl"."LangCd"
    where
      cast(
        substr("Cal_BusCal_CCD"."MonthPerCd", 1, 4) || '-' || substr("Cal_BusCal_CCD"."MonthPerCd", 5, 2) || '-' || '01' as date
      ) between cast(
        (
          case
            when dayofmonth(current_date) > 19 then (
              ADD_MONTHS(current_date, -3) - CAST(
                EXTRACT(
                  DAY
                  FROM
                    ADD_MONTHS(current_date, -3)
                ) AS INTERVAL DAY
              ) + INTERVAL '1' DAY
            )
            else (
              ADD_MONTHS(current_date, -2) - CAST(
                EXTRACT(
                  DAY
                  FROM
                    ADD_MONTHS(current_date, -2)
                ) AS INTERVAL DAY
              ) + INTERVAL '1' DAY
            )
          end
        ) as date
      )
      and cast(
        (
          case
            when dayofmonth(current_date) > 19 then (
              ADD_MONTHS(
                (
                  ADD_MONTHS(current_date, 2) - CAST(
                    EXTRACT(
                      DAY
                      FROM
                        ADD_MONTHS(current_date, 2)
                    ) AS INTERVAL DAY
                  ) + INTERVAL '1' DAY
                ),
                1
              ) - INTERVAL '1' DAY
            )
            else (
              ADD_MONTHS(
                (
                  ADD_MONTHS(current_date, 3) - CAST(
                    EXTRACT(
                      DAY
                      FROM
                        ADD_MONTHS(current_date, 3)
                    ) AS INTERVAL DAY
                  ) + INTERVAL '1' DAY
                ),
                1
              ) - INTERVAL '1' DAY
            )
          end
        ) as date
      )
      and (
        case
          when (
            "SO_DocType"."Cntrct_CO_OrdTypeCd" = 'CN'
            or INDEX(
              "SO_Unshpble"."CnclDtWi5DaysFromSysDtInd" || "SO_Unshpble"."CCD_PastCnclDtInd" || "SO_Unshpble"."CnclRiskInd" || "SO_Unshpble"."CrdtHoldInd" || "SO_Unshpble"."DlvryHdrBlckInd" || "SO_Unshpble"."DlvrySchedLnBlckInd" || "SO_Unshpble"."IncmplOrdInd",
              'Y'
            ) > 0
          ) then 'Y'
          else 'N'
        end
      ) = 'N'
      and "so_core_v"."SuperGeoID" = 4
      and "so_core_v"."SlsOrgCd" in ('2000', '3600', '3700', '3900', '4000', '4210')
      and "so_core_v"."DivCd" in ('10', '20', '30')
      and "Plnt"."PlntIdCd" in ('1060', '1064', '1065', '1067')
      and "so_core_v"."SoldToNbr" in ('0000102094','0000107204','0000107878','0000109180','0000114814','0000119530','0000119570','0000127126','0000128876','0000135558','0000174042','0000190391','0000194382','0000245198','0000249526','0000257409','0000260012','0000285399','0000296710','0000297885','0000299820','0000326614','0000354749','0000369754','0000388191','0000387645','0000388546','0000390027','0000393660','0000420436','0000465992','0000444039')
      and (
        case
          "so_core_v"."DistribMthdCd"
          when '*UNK*' then ''
          else "so_core_v"."DistribMthdCd"
        end
      ) in ('DC')
      and "so_core_v"."ActvInd" = 'Y'
      and "Cal_BusCal_CCD"."CalDt" > add_months(current_date, -48)
      and "Cal_BusCal_CRD"."CalDt" > add_months(current_date, -48)
    group by
      (
        case
          when 'C2' in ('1') then "so_core_v"."SoldToNbr"
        end
      ),
      (
        case
          when 'C3' in ('1') then (
            coalesce(
              "Cust_l_Sold_To"."CustDesc",
              "Cust_Sold_To"."CustNm"
            )
          )
        end
      ),
      (
        case
          when 'C4' in ('1') then "so_core_v"."ShipToNbr"
        end
      ),
      (
        case
          when 'C5' in ('1') then (
            coalesce(
              "Cust_l_Ship_To"."CustDesc",
              "Cust_Ship_to_so_core_"."CustNm"
            )
          )
        end
      ),
      (
        case
          when 'DC' in ('1') then "SlsRep_so_core_"."SlsRepNm"
        end
      ),
      (
        case
          when 'C9' in ('1') then (
            case
              "so_core_v"."DistribMthdCd"
              when '*UNK*' then ''
              else "so_core_v"."DistribMthdCd"
            end
          )
        end
      ),
      (
        case
          "so_core_v"."CRD"
          when cast('0001-01-01' as date) then NULL
          else "so_core_v"."CRD"
        end
      ),
      "Cal_BusCal_CRD"."MonthPerCd",
      "Cal_BusCal_CCD"."MonthPerCd",
      (
        case
          when 'E9' in ('1') then "Plnt"."PlntIdCd"
        end
      ),
      "so_core_v"."DivCd",
      "SO_DocType"."SO_DocTypeCd",
      "so_core_v"."SO_HdrNbr",
      "so_core_v"."SO_ItmNbr",
      (
        case
          "ProdtGPI"."ProdtCd"
          when '*UNK*' then ''
          else "ProdtGPI"."ProdtCd"
        end
      ),
      (
        coalesce(
          (
            NULLIF("ProdtLocizedTransl"."LocizedProdtNm", ' ')
          ),
          "ProdtGPI"."ProdtLglLongNm"
        )
      ),
      (
        case
          when 'C12' in ('1') then "GlblCatSum"."GlblCatSumDesc"
        end
      )
    having
      sum(
        zeroifnull("Cvrg_SO_SchedLn_Trnspd"."RsrvdToOnHandInvQty")
      ) / (
        NULLIF(
          sum(
            zeroifnull(
              "Cvrg_SO_SchedLn_Trnspd"."RmaingRptgCnfrmdToDlvrQty"
            )
          ),
          0
        )
      ) > 0
  ) "T0"

1 个答案:

答案 0 :(得分:3)

DayOfMonth不是Teradata SQL,而是ODBC函数,只需使用标准SQL extract(day from current_date)