update packing price

本文介绍了一个ABAP程序实例,该程序用于检查销售订单中是否已附加包装价格,并根据客户采购订单进行价格计算及货币转换。通过条件判断和数据库查询实现业务逻辑处理,确保了定价准确性。

FORM. FRM_KONDI_WERT_980.
*{   INSERT         SDQK9A1SJD                                        2
******20100325 by five
  DATA : custpo LIKE vbak-bstnk,
         amount LIKE konp-kbetr,
         zvbeln LIKE vbrp-vbeln,
         zposnr LIKE vbrp-posnr,
         zwaerk LIKE komk-waerk,
         zknumv LIKE vbrk-knumv,
         zcount  type i,
         zflag(1) type c,
         zreason(100) type c,
         zint type i.

  DATA:   v_vbeln  LIKE vbak-vbeln,
          s_vbeln  LIKE vbak-vbeln,
          v_posnr  LIKE vbap-posnr.
  DATA: t_er        TYPE tcurr-ukurs, " exchange rates
        t_ff        TYPE tcurr-ffact, " from currency
        t_lf        TYPE tcurr-tfact, " to currency
        ld_erate LIKE komk-kurrf.

  IF komk-vkorg = 'PELH' AND komk-vtweg = 'C0'.
   clear:v_vbeln,v_posnr,custpo.
**** get SO number
    SELECT SINGLE vgbel vgpos INTO (v_vbeln, v_posnr)
    FROM lips
    WHERE vbeln = komp-vgbel
    AND posnr = komp-vgpos.

*******get customer po
    SELECT SINGLE vbak~bstnk
    INTO (custpo)
    FROM vbak
    WHERE vbak~vbeln = v_vbeln.

********check billing if has packing price
select distinct vbeln into S_VBELN from lips where VGBEL = v_vbeln.
  if zflag <> 'Y'.
  clear :ZVBELN,ZPOSNR,ZKNUMV.
tableS:VBRK.
  SELECT distinct VBRP~VBELN VBRP~POSNR VBRK~KNUMV
  INTO (ZVBELN,ZPOSNR,ZKNUMV)
  FROM VBRP INNER JOIN VBRK
  ON VBRP~VBELN = VBRK~VBELN
  WHERE VBRP~VGBEL = S_VBELN
  and VBRP~VBELN like '5%'.
  if sy-subrc = 0.

    SELECT SINGLE *
    FROM VBRK WHERE SFAKN = ZVBELN.
    if sy-subrc <> 0.
      clear :zcount.
      SELECT count( * ) into zcount
      FROM KONV
      WHERE KNUMV = ZKNUMV
      AND KSCHL = 'ZPK0'
      and KPOSN = ZPOSNR .
      if zcount >= 1 .
      zflag = 'Y'.
      exit.
      endif.

    endif.

  endif.
  endselect.
 ENDIF.
endselect.

IF ZFLAG = 'Y'
   and ( ZKNUMV = xkomv-KNUMV )
   and ( ZPOSNR = xkomv-kposn ).
ELSEif ZFLAG = 'Y' .
concatenate ZVBELN ' has append packing price in line: ' ZPOSNR
' for PO :' custpo into zreason.

CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
  EXPORTING
   TITEL              = 'Warning !!'
   textline1          = zreason
   textline2          = 'So price will be zero'
   START_COLUMN       = 10
   START_ROW          = 6 .

ENDIF.

IF ZFLAG = ''.
    IF NOT custpo IS INITIAL.
      CALL FUNCTION 'ZRFC_SD_PCE_0084'
           EXPORTING
                zcustpo = custpo
           IMPORTING
                zamount = amount.

      zwaerk = 'USD'.

      IF komk-waerk <> zwaerk .
        CALL FUNCTION 'READ_EXCHANGE_RATE'
            EXPORTING
*       CLIENT                  = SY-MANDT
              date                    = sy-datum
              foreign_currency        = zwaerk
              local_currency          = komk-waerk
          type_of_rate            = 'M'    " SAP standard exchange rates
* type
*       EXACT_DATE              = ' '
           IMPORTING
              exchange_rate           = t_er   " exchange rates
              foreign_factor          = t_ff   " foreign factor
              local_factor            = t_lf   " local factor
*       DERIVED_RATE_TYPE       =
*       FIXED_RATE              =
*       OLDEST_RATE_FROM        =
           EXCEPTIONS
             no_rate_found           = 1
             no_factors_found        = 2
             no_spread_found         = 3
             derived_2_times         = 4
             overflow                = 5 .
        IF sy-subrc = 0.
          ld_erate = t_er / ( t_ff / t_lf ).
        ENDIF.


        IF xkomv-kbetr = '' .
          xkwert = ( amount * ld_erate ) / 10000000.
          xkomv-kbetr = amount.
        ELSE.
          xkwert = ( xkomv-kbetr * ld_erate ) / 10000000.
        ENDIF.

      ELSE.
        ld_erate = '1.00000'.
        IF xkomv-kbetr = ''.
          xkwert = ( amount * ld_erate ) / 100000.
          xkomv-kbetr = amount.
        ELSE.
          xkwert = ( xkomv-kbetr * ld_erate ) / 100000.
        ENDIF.
      ENDIF.

      xkomv-waers = zwaerk.
      xkomv-kkurs = ld_erate.
      if xkwert = 0.
     
      CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
  EXPORTING
   TITEL              = 'Warning !!'
   textline1          = 'packing price is zero'
   textline2          = 'pls check FG pack code & price'
   START_COLUMN       = 10
   START_ROW          = 6 .
      endif.
     
     
    ENDIF.
  ENDIF.


  ENDIF.

 

*}   INSERT
ENDFORM.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14397246/viewspace-665761/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/14397246/viewspace-665761/

把下列mysql语句转换成oracle语法,注意字符转换,并在行首添加一列sid自增主键 ,行末添加sc varchar(100) '数据来源' 和 dt varchar(200) '入库时间' 两个字段以及添加注释 如果含有'_op'字段,则转换为 op,返还语句即可 不需要说明,先写建表语句和表注释 其次序列 然后触发器 -- gm.scm_dom_trade_sale_order definition CREATE TABLE `ods_dom_td_sl_od_agr ` ( `id` varchar(36) NOT NULL, `create_by` varchar(50) DEFAULT NULL COMMENT '创建人', `create_time` datetime DEFAULT NULL COMMENT '创建日期', `update_by` varchar(50) DEFAULT NULL COMMENT '更新人', `update_time` datetime DEFAULT NULL COMMENT '更新日期', `sys_org_code` varchar(64) DEFAULT NULL COMMENT '所属部门', `trade_sale_order_no` varchar(50) DEFAULT NULL COMMENT '订单号', `trade_sale_contract_no` varchar(50) DEFAULT NULL COMMENT '合同号', `customer_id` varchar(200) DEFAULT NULL COMMENT '客户ID', `customer_name` varchar(200) DEFAULT NULL COMMENT '客户名称', `order_amount` decimal(18,2) DEFAULT NULL COMMENT '订单金额(元)', `status` varchar(5) DEFAULT NULL COMMENT '状态', `instance_id` varchar(36) DEFAULT NULL COMMENT '审批实例ID', `files` text COMMENT '附件', `files_images` text COMMENT '附件图片', `trade_sale_contract_id` varchar(36) DEFAULT NULL COMMENT '合同ID', `product_packing` varchar(32) DEFAULT NULL COMMENT '包装', `pay_way` varchar(5) DEFAULT NULL COMMENT '支付方式', `dom_trade_type` varchar(5) DEFAULT NULL COMMENT '业务类型', `is_dianjia` varchar(5) DEFAULT NULL COMMENT '点价', `use_seal` varchar(5) DEFAULT NULL COMMENT '用印', `use_seal_info` text COMMENT '用印数据', `create_user_name` varchar(32) DEFAULT NULL COMMENT '创建人姓名', `delete_flag` varchar(4) DEFAULT NULL COMMENT '删除', `order_amount1` decimal(18,2) DEFAULT NULL COMMENT '订单金额(元)', `old_sale_order_id` varchar(36) DEFAULT NULL COMMENT '主订单ID', `remark` varchar(200) DEFAULT NULL COMMENT '备注', `old_sale_order_no` varchar(32) DEFAULT NULL COMMENT '主订单号', `relation_instance_id` varchar(200) DEFAULT NULL COMMENT '关联审批ID', `relation_buss_no` varchar(200) DEFAULT NULL COMMENT '关联审批单', `price_mode` varchar(4) DEFAULT NULL COMMENT '一口价模式', `_op` varchar(4) DEFAULT 'r' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; comment '内贸销售订单 '
08-23
把下列mysql语句转换成oracle语法,注意字符转换,并在行首添加一列sid自增主键 ,行末添加sc varchar(100) '数据来源' 和 dt varchar(200) '入库时间' 两个字段以及添加注释 如果含有'_op'字段,则转换为 op,返还语句即可 不需要说明,先写建表语句和表注释 其次序列 然后触发器 -- gm.scm_dom_trade_pur_order definition CREATE TABLE `ods_dom_td_pur_od_agr ` ( `id` varchar(36) NOT NULL, `create_by` varchar(50) DEFAULT NULL COMMENT '创建人', `create_time` datetime DEFAULT NULL COMMENT '创建日期', `update_by` varchar(50) DEFAULT NULL COMMENT '更新人', `update_time` datetime DEFAULT NULL COMMENT '更新日期', `sys_org_code` varchar(64) DEFAULT NULL COMMENT '所属部门', `trade_pur_order_no` varchar(50) DEFAULT NULL COMMENT '订单号', `trade_pur_contract_id` varchar(36) DEFAULT NULL COMMENT '采购合同ID', `trade_pur_contract_no` varchar(50) DEFAULT NULL COMMENT '采购合同编号', `dom_trade_type` varchar(5) DEFAULT NULL COMMENT '业务类型', `supplier_id` varchar(36) DEFAULT NULL COMMENT '供应商ID', `supplier_name` varchar(50) DEFAULT NULL COMMENT '供应商名称', `order_amount` decimal(18,2) DEFAULT NULL COMMENT '订单金额(元)', `status` varchar(5) DEFAULT NULL COMMENT '状态', `files` text COMMENT '附件', `files_images` text COMMENT '附件图片', `product_packing` varchar(10) DEFAULT NULL COMMENT '包装', `pay_way` varchar(5) DEFAULT NULL COMMENT '支付方式', `is_dianjia` varchar(5) DEFAULT NULL COMMENT '点价', `instance_id` varchar(36) DEFAULT NULL COMMENT '审批流ID', `use_seal` varchar(5) DEFAULT NULL COMMENT '用印', `use_seal_info` text COMMENT '用印数据', `create_user_name` varchar(32) DEFAULT NULL COMMENT '创建人姓名', `delete_flag` varchar(4) DEFAULT NULL COMMENT '删除', `is_stockin` varchar(4) DEFAULT NULL COMMENT '是否入库', `remark` varchar(200) DEFAULT NULL COMMENT '备注', `old_pur_order_id` varchar(36) DEFAULT NULL COMMENT '主采购订单ID', `old_pur_order_no` varchar(32) DEFAULT NULL COMMENT '主采购订单号', `relation_instance_id` varchar(200) DEFAULT NULL COMMENT '关联审批ID', `relation_buss_no` varchar(200) DEFAULT NULL COMMENT '关联审批单', `future_code` varchar(50) DEFAULT NULL COMMENT '期货代码', `future_price` decimal(18,2) DEFAULT NULL COMMENT '期货价格', `_op` varchar(4) DEFAULT 'r' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; comment '内贸采购订单 '
08-23
if OBJECT_ID('tempdb..#temp') is not null drop table #temp; declare @domain smallint; select @domain=domain from domain where current_flag=1; DECLARE @stone_places INT; SELECT @stone_places = CAST(value AS INT) FROM ops_default WHERE comp_code = 56 AND code = 6; DECLARE @total INT; CREATE TABLE #temp ( domain smallint, comp_code smallint, order_no int, sub_order_no smallint, job_order_no smallint, split_order_no smallint, dec_stock_type INT, batch_no int, dec_date DATETIME, qty INT, total_weight DECIMAL(18, 4), export_amount MONEY, total_labour MONEY, total_labour_USD MONEY, total_labour_CNY MONEY, receive_district SMALLINT, receive_district_desc NVARCHAR(50), ver_no SMALLINT, adding_labour_cost MONEY, adding_labour_cost_USD MONEY, adding_labour_cost_CNY MONEY, export_amount_HKD MONEY, export_amount_CNY MONEY, total int, aes_export_amount MONEY, aes_mark_good_value MONEY, other_accessory_export_amount MONEY, export_amount_sum MONEY, gold_export_amount MONEY, sync_flag int, last_sync_date datetime, last_sync_by varchar(10) ); insert into #temp(domain,comp_code , order_no , sub_order_no , job_order_no , split_order_no , dec_date,receive_district,ver_no, adding_labour_cost,total_labour,qty,dec_stock_type,batch_no,receive_district_desc,sync_flag,last_sync_date,last_sync_by,total_weight) select @domain,comp_code , order_no , sub_order_no , job_order_no , split_order_no , dec_date,rd.receive_district,ver_no, adding_labour_cost,total_labour,qty,dec_stock_type,batch_no,rd.description as receive_district_desc,sync_flag,last_sync_date,last_sync_by, ROUND(gold_weight + accessories_weight + other_accessories_weight, 2) from customs_master cm left join receive_district rd on cm.receive_district = rd.receive_district WHERE cm.info_number = '' and synchro_mid_flag = 1 and comp_code = 56 ; UPDATE t SET adding_labour_cost_USD = ROUND(adding_labour_cost * rate_value_us, 2), total_labour_USD = ROUND(total_labour * rate_value_us, 2) from #temp t inner join rate r on r.date_from <= t.dec_date AND r.date_to >= t.dec_date; UPDATE t SET adding_labour_cost_CNY = ROUND(adding_labour_cost_USD * rate_value_cn, 2), total_labour_CNY = ROUND(total_labour_USD * rate_value_cn, 2) from #temp t inner join rate r on r.date_from <= t.dec_date AND r.date_to >= t.dec_date; UPDATE #temp SET gold_export_amount =gold_result.gold_export_amount FROM #temp AS temp INNER JOIN ( select [domain],[comp_code],[order_no],[sub_order_no],[job_order_no],[split_order_no],[batch_no], sum(gold_export_amount) as gold_export_amount from (SELECT #temp.[domain], #temp.[comp_code], #temp.[order_no], #temp.[sub_order_no], #temp.[job_order_no], #temp.[split_order_no], #temp.[batch_no], dec_gold_accessories.dec_gold_no , ROUND( ROUND( SUM( CASE WHEN ISNULL(dec_stock_type_ref.gold_loss_rate, 0) = 1 THEN 0 ELSE dec_gold_accessories.gold_weight / (1 - ISNULL(dec_stock_type_ref.gold_loss_rate, 0)) END ), 4 )* dec_gold_accessories.dec_unit_price,2) AS gold_export_amount FROM #temp INNER JOIN dbo.dec_stock_type ON dec_stock_type.dec_stock_type = #temp.dec_stock_type INNER JOIN dbo.dec_hk_stock_type ON dec_hk_stock_type.dec_hk_stock_type = dec_stock_type.dec_hk_stock_type INNER JOIN dbo.dec_gold_accessories ON dec_gold_accessories.domain = #temp.domain AND dec_gold_accessories.comp_code = #temp.comp_code AND dec_gold_accessories.order_no = #temp.order_no AND dec_gold_accessories.sub_order_no = #temp.sub_order_no AND dec_gold_accessories.job_order_no = #temp.job_order_no AND dec_gold_accessories.split_order_no = #temp.split_order_no AND dec_gold_accessories.batch_no = #temp.batch_no LEFT JOIN dbo.product_gold_type ON dec_gold_accessories.dec_gold_no = product_gold_type.gold_type AND gold_group2 <> '0' LEFT JOIN dbo.dec_stock_type_ref ON dec_stock_type_ref.dec_stock_type = #temp.dec_stock_type AND dec_stock_type_ref.dec_gold_no = dec_gold_accessories.dec_gold_no GROUP BY #temp.[domain], #temp.[comp_code], #temp.[order_no], #temp.[sub_order_no], #temp.[job_order_no], #temp.[split_order_no], #temp.[batch_no], dec_gold_accessories.dec_gold_no,dec_gold_accessories.dec_unit_price ) AS gold_detail_result group by [domain],[comp_code],[order_no],[sub_order_no],[job_order_no],[split_order_no],[batch_no] ) AS gold_result ON temp.[domain] = gold_result.[domain] AND temp.[comp_code] = gold_result.[comp_code] AND temp.[order_no] = gold_result.[order_no] AND temp.[sub_order_no] = gold_result.[sub_order_no] AND temp.[job_order_no] = gold_result.[job_order_no] AND temp.[split_order_no] = gold_result.[split_order_no] AND temp.[batch_no] = gold_result.[batch_no]; IF OBJECT_ID('tempdb..#temp_accessories') IS NOT NULL DROP TABLE #temp_accessories; SELECT a.*, CAST(0 AS SMALLINT) AS dec_item_type, itm.item_type, single_wgt = ROUND( a.weight / (CASE (a.qty * a.packing_qty) WHEN 0 THEN 1 ELSE (a.qty * a.packing_qty) END ), @stone_places ) INTO #temp_accessories FROM #temp AS temp INNER JOIN dbo.accessories AS a ON temp.domain = a.domain AND temp.comp_code = a.comp_code AND temp.order_no = a.order_no AND temp.sub_order_no = a.sub_order_no AND temp.job_order_no = a.job_order_no AND temp.split_order_no = a.split_order_no AND a.cancel_flag = 0 LEFT JOIN item_code_master itm ON a.item_code = itm.item_code; UPDATE #temp_accessories SET dec_item_type = ditr.dec_item_type FROM #temp_accessories aes INNER JOIN dec_item_type_ref ditr ON aes.item_code = ditr.item_code WHERE aes.item_type <> 'A'; UPDATE #temp_accessories SET dec_item_type = ditr.dec_item_type FROM #temp_accessories aes INNER JOIN dec_item_type_ref ditr ON aes.item_code = ditr.item_code AND single_wgt <= ditr.max_wgt AND single_wgt >= ditr.min_wgt WHERE aes.item_type = 'A'; UPDATE #temp SET aes_mark_good_value = aes_result.aes_mark_good_value, aes_export_amount = round(aes_result.aes_export_amount,2) FROM #temp AS temp INNER JOIN (select [domain],[comp_code],[order_no],[sub_order_no],[job_order_no],[split_order_no],[batch_no], sum(aes_export_amount) as aes_export_amount,SUM(cost) AS aes_mark_good_value from (SELECT #temp.[domain], #temp.[comp_code], #temp.[order_no], #temp.[sub_order_no], #temp.[job_order_no], #temp.[split_order_no], #temp.[batch_no], dec_item_type_ref.dec_item_type, ROUND(ROUND(SUM(a.weight * convert_weight_times),4) * dec_item_type.dec_unit_price,2) AS aes_export_amount, SUM(cost) AS cost FROM #temp INNER JOIN dbo.dec_stock_type ON dec_stock_type.dec_stock_type = #temp.dec_stock_type INNER JOIN dbo.dec_hk_stock_type ON dec_hk_stock_type.dec_hk_stock_type = dec_stock_type.dec_hk_stock_type INNER JOIN #temp_accessories AS a ON #temp.domain = a.domain AND #temp.order_no = a.order_no AND #temp.sub_order_no = a.sub_order_no AND #temp.job_order_no = a.job_order_no AND #temp.split_order_no = a.split_order_no AND a.cancel_flag = 0 LEFT JOIN dbo.item_code_master AS icm ON icm.item_code = a.item_code LEFT JOIN dbo.dec_item_type_ref ON dec_item_type_ref.item_code = a.item_code and ( round(a.weight/(case (a.qty*a.packing_qty) when 0 then 1 else (a.qty*a.packing_qty) end ), icm.decimal_place) <= case when icm.item_type='A' then dec_item_type_ref.max_wgt end or dec_item_type_ref.max_wgt = case when icm.item_type <> 'A' then dec_item_type_ref.max_wgt end ) and ( round(a.weight/(case (a.qty*a.packing_qty) when 0 then 1 else (a.qty*a.packing_qty) end ), icm.decimal_place) >= case when icm.item_type='A' then dec_item_type_ref.min_wgt end or dec_item_type_ref.min_wgt = case when icm.item_type <> 'A' then dec_item_type_ref.min_wgt end ) LEFT JOIN dbo.dec_item_type ON dec_item_type.dec_item_type = dec_item_type_ref.dec_item_type GROUP BY #temp.[domain], #temp.[comp_code], #temp.[order_no], #temp.[sub_order_no], #temp.[job_order_no], #temp.[split_order_no], #temp.[batch_no], dec_item_type.dec_unit_price,dec_item_type_ref.dec_item_type )AS aes_Detail_Result group by [domain],[comp_code],[order_no],[sub_order_no],[job_order_no],[split_order_no],[batch_no] ) AS aes_result ON temp.[domain] = aes_result.[domain] AND temp.[comp_code] = aes_result.[comp_code] AND temp.[order_no] = aes_result.[order_no] AND temp.[sub_order_no] = aes_result.[sub_order_no] AND temp.[job_order_no] = aes_result.[job_order_no] AND temp.[split_order_no] = aes_result.[split_order_no] AND temp.[batch_no] = aes_result.[batch_no]; UPDATE #temp SET other_accessory_export_amount = other_accessory_result.other_accessory_export_amount FROM #temp AS temp INNER JOIN (select [domain],[comp_code],[order_no],[sub_order_no],[job_order_no],[split_order_no],[batch_no], sum(other_accessory_export_amount) as other_accessory_export_amount, sum(other_accessory_mark_good_value) as other_accessory_mark_good_value from ( SELECT #temp.[domain], #temp.[comp_code], #temp.[order_no], #temp.[sub_order_no], #temp.[job_order_no], #temp.[split_order_no], #temp.[batch_no], dec_other_accessory.other_type, ROUND(SUM(dec_other_accessory.weight * other_type.dec_unit_price), 2) AS other_accessory_export_amount, ROUND(SUM(dec_other_accessory.weight * other_type.dec_unit_price), 2) AS other_accessory_mark_good_value FROM #temp INNER JOIN dbo.dec_stock_type ON dec_stock_type.dec_stock_type = #temp.dec_stock_type INNER JOIN dbo.dec_hk_stock_type ON dec_hk_stock_type.dec_hk_stock_type = dec_stock_type.dec_hk_stock_type INNER JOIN dbo.dec_other_accessory ON dec_other_accessory.domain = #temp.domain AND dec_other_accessory.comp_code = #temp.comp_code AND dec_other_accessory.order_no = #temp.order_no AND dec_other_accessory.sub_order_no = #temp.sub_order_no AND dec_other_accessory.job_order_no = #temp.job_order_no AND dec_other_accessory.split_order_no = #temp.split_order_no AND dec_other_accessory.batch_no = #temp.batch_no LEFT JOIN dbo.other_type ON other_type.other_type = dec_other_accessory.other_type GROUP BY #temp.[domain], #temp.[comp_code], #temp.[order_no], #temp.[sub_order_no], #temp.[job_order_no], #temp.[split_order_no], #temp.[batch_no], dec_other_accessory.other_type )AS other_accessory_detail_result group by [domain],[comp_code],[order_no],[sub_order_no],[job_order_no],[split_order_no],[batch_no] ) AS other_accessory_result ON temp.[domain] = other_accessory_result.[domain] AND temp.[comp_code] = other_accessory_result.[comp_code] AND temp.[order_no] = other_accessory_result.[order_no] AND temp.[sub_order_no] = other_accessory_result.[sub_order_no] AND temp.[job_order_no] = other_accessory_result.[job_order_no] AND temp.[split_order_no] = other_accessory_result.[split_order_no] AND temp.[batch_no] = other_accessory_result.[batch_no]; UPDATE #temp SET export_amount_sum = t.export_amount_sum from #temp inner join ( select (SUM(total_labour_USD) + SUM(adding_labour_cost_USD) + SUM(gold_export_amount) + SUM(aes_export_amount) + SUM(other_accessory_export_amount)) as export_amount_sum, comp_code,order_no,sub_order_no,job_order_no,split_order_no,batch_no from #temp group by comp_code,order_no,sub_order_no,job_order_no,split_order_no,batch_no ) as t on #temp.comp_code = t.comp_code and #temp.order_no = t.order_no and #temp.sub_order_no = t.sub_order_no and #temp.job_order_no = t.job_order_no and #temp.split_order_no = t.split_order_no and #temp.batch_no = t.batch_no; WITH GroupedData AS ( select dec_date , ver_no , receive_district , receive_district_desc , rtrim(last_sync_by) AS last_sync_by, last_sync_date, fr.flag_desc_cn as syncFlagDesc, sum(qty) OVER(PARTITION BY dec_date, ver_no,receive_district) as qty , sum(adding_labour_cost) OVER(PARTITION BY dec_date, ver_no,receive_district) as adding_labour_cost , sum(total_labour) OVER(PARTITION BY dec_date, ver_no,receive_district) as total_labour , sum(total_weight) OVER(PARTITION BY dec_date, ver_no,receive_district) as total_weight , sum(total_labour_USD) OVER(PARTITION BY dec_date, ver_no,receive_district) as total_labour_USD , sum(total_labour_CNY) OVER(PARTITION BY dec_date, ver_no,receive_district) as total_labour_CNY , sum(adding_labour_cost_USD) OVER(PARTITION BY dec_date, ver_no,receive_district) as adding_labour_cost_USD , sum(adding_labour_cost_CNY) OVER(PARTITION BY dec_date, ver_no,receive_district) as adding_labour_cost_CNY , sum(export_amount_sum) OVER(PARTITION BY dec_date, ver_no,receive_district) as export_amount_sum , COUNT(*) OVER(PARTITION BY dec_date, ver_no,receive_district) AS total, min(sync_flag) OVER(PARTITION BY dec_date, ver_no,receive_district) as sync_flag, ROW_NUMBER() OVER( PARTITION BY dec_date, ver_no,receive_district ORDER BY last_sync_date DESC ) AS time_rank from #temp t inner join flag_reference fr on fr.flag_id = t.sync_flag and fr.flag_group = 'sync_flag' ) select dec_date , ver_no , receive_district , receive_district_desc , last_sync_by, syncFlagDesc, qty , adding_labour_cost , total_labour , total_weight , total_labour_USD , total_labour_CNY , adding_labour_cost_USD , adding_labour_cost_CNY , export_amount_sum , total, sync_flag, last_sync_date from GroupedData where time_rank = 1 OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY ; if OBJECT_ID('tempdb..#temp') is not null drop table #temp;sqlserver 会报什么错
08-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值