0

在 DbaaS 上从 SQL Server 2016 迁移到 2019 时,我收到此错误:

消息 102,级别 15,状态 1,服务器 p2fm1sql414\SQL01,过程 usp_sales_record_1020,第 75 行
'*=' 附近的语法不正确

见查询:

  select @sql_1 = "
  --BEGIN TRANSACTION
     insert into SalesFactor.dbo.tbl_cmfsales
     select a.asof_yyyymm ,
            a.bllg_doc_id ,
            a.bllg_doc_ref_id ,
            a.bllg_yyyymm ,
            a.cfm_opr_cd  ,
            a.cfm_opr_dsc ,
            a.dlv_doc_id    ,
            a.dstrb_chnl_cd ,
            a.dstrb_chnl_dsc ,
            a.indus_ky_cd ,
            a.indus_ky_dsc ,
            mtd_bllg_amt    = (1 - abs(sign(a.bllg_yyyymm - a.asof_yyyymm))) * a.mtd_bllg_amt,
            mtd_bllg_qty    = (1 - abs(sign(a.bllg_yyyymm - a.asof_yyyymm))) * a.mtd_bllg_qty,
            a.ord_rsn_cd  ,
            a.pay_cst_id ,
            a.plt_cd  ,
            a.sld_cst_id ,
            a.shp_cst_id ,
            a.sll_co_cd ,
            a.sls_org_cd ,
            a.sls_ord_doc_ty_cd ,
            a.sls_ord_doc_ty_dsc ,
            a.sls_ord_id ,
            a.sls_org_dsc,
            a.shp_cst_ctry_dsc,
              returns = case when a.sls_ord_doc_ty_cd not in('or','zdpa') then ((1 - abs(sign(a.bllg_yyyymm - a.asof_yyyymm))) * a.mtd_bllg_amt)
                             else 0 end,
            a.shp_cst_ctry_cd ,
            b.cst_nm ,
            b.addr_2_nm ,
            b.addr_3_nm ,
            b.addr_4_nm ,
            b.addr_cty ,
            rgn_cd = isnull(b.rgn_cd,' '),
            b.post_cd ,
            b.cst_srch_nm ,
            b.cst_acct_grp_cd ,
            b.cst_acct_grp_dsc ,
            UsAmt =    ((1 - abs(sign(a.bllg_yyyymm - a.asof_yyyymm))) * a.mtd_bllg_amt) * charindex('US',a.shp_cst_ctry_cd),
            OtherAmt = ((1 - abs(sign(a.bllg_yyyymm - a.asof_yyyymm))) * a.mtd_bllg_amt) * (1-abs(sign((charindex('US',a.shp_cst_ctry_cd)))-0)),
            RnaDpa =   ((1 - abs(sign(a.bllg_yyyymm - a.asof_yyyymm))) * a.mtd_bllg_amt) * charindex('zdpa',a.sls_ord_doc_ty_cd) ,
            DpaSales = ((1 - abs(sign(a.bllg_yyyymm - a.asof_yyyymm))) * a.mtd_bllg_amt) * charindex('or',a.sls_ord_doc_ty_cd) ,
            quarter = 'Q' + '" + @pass + "',
            year    = '" + @yyyy + "',
            status =    case when shp_cst_ctry_cd = 'US' then 'U.S.'
                               else'Foreign' end,
            warehouse = case  when substring(a.plt_cd,2,2) = 'ch' Then 'AZ'
                              when substring(a.plt_cd,2,2) = 'wa' Then 'WA'
                              when substring(a.plt_cd,2,2) = 'or' Then 'OR'
                              when substring(a.plt_cd,2,2) = 'sc' Then 'CA'
                              when substring(a.plt_cd,2,2) = 'fm' Then 'CA'
                              when substring(a.plt_cd,2,2) = 'ca' Then 'CA'
                              else 'Foreign' end,
            type =      case when a.shp_cst_ctry_cd = 'US' then '1'
                              else '2' end,
            pay_cst_nm = ' ',
            pay_state = ' '
       from data_store.dbo.tbl_billed_orders_" + @yyyy + @mm + " a, tpdb.dbo.tbl_cst_mstr b
       " + @str_where + " and  a.shp_cst_id *= b.cst_id and b.cst_acct_grp_cd not in('ZISH','ZISP','ZPRC')

--COMMIT TRANSACTION
"

当我在 SQL Server 2016 上运行时,我能够执行此查询,但在迁移过程中它会因上述错误而失败?

关于此查询的任何更改的任何建议?

4

2 回答 2

4

您正在使用古老的连接样式*=
将其更改为左连接,它将再次起作用。

请停止使用旧的连接样式,这在很久以前就已被弃用。

from data_store.dbo.tbl_billed_orders_" + @yyyy + @mm + " a, tpdb.dbo.tbl_cst_mstr b
       " + @str_where + " and  a.shp_cst_id *= b.cst_id and b.cst_acct_grp_cd not in('ZISH','ZISP','ZPRC')

它应该更像这样

from data_store.dbo.tbl_billed_orders_" + @yyyy + @mm + " a
  left join tpdb.dbo.tbl_cst_mstr b
    ON a.shp_cst_id = b.cst_id 
where b.cst_acct_grp_cd not in('ZISH','ZISP','ZPRC')

另请参阅此答案

于 2022-02-11T07:08:04.697 回答
0

尝试更改此行:

" + @str_where + " and  a.shp_cst_id *= b.cst_id and b.cst_acct_grp_cd not in('ZISH','ZISP','ZPRC')` to `" + @str_where + " and  a.shp_cst_id = b.cst_id and b.cst_acct_grp_cd not in('ZISH','ZISP','ZPRC')
于 2022-02-11T07:06:28.190 回答