40  
泰格清除超大额销售
作者: 吴翔宇 于 2020年06月22日 发布在分类 / 软件 / 泰格 / 至尊 下,并于 2022年04月06日 编辑

以下三条清除超大额销售语句
select * from pos_t_payflow where pay_amt>10000
update pos_t_payflow set pay_amt=sale_amt where flow_no='小票销售流水号' and flow_id=1

delete pos_t_payflow where flow_no='小票销售流水号' and flow_id=1


如果上面语句无效,使用下面语句:

/*查询付款金额大于10万的销售流水*/
select * from pos_t_payflow where pay_amt>100000

/*删除前台某笔交易*/
declare @branch_no varchar(4), @flow_no varchar(14), @adt_from datetime, @adt_to datetime

set @branch_no = '01'             /*分店编号*/
set @adt_from = '2013-07-14'      /*错误日期*/
set @flow_no = '01201307140003'   /*错误的小票号*/


set @adt_to = convert(char(10), @adt_from, 120) + ' 23:59:59'

delete from pos_t_payflow
 where flow_no = @flow_no and branch_no = @branch_no
delete from pos_t_saleflow 
 where flow_no = @flow_no and branch_no = @branch_no

if not object_id('tempdb..#t') is null
  drop table #t

select branch_no, item_no, oper_date = convert(char(10), oper_date, 120),
sale_qty = sum(case when sale_way='A' then sale_qty else 0 end),
ret_qty = sum(case when sale_way='B' then sale_qty else 0 end),
sale_amt = sum(case when sale_way='A' then sale_amt else 0 end),
ret_amt = sum(case when sale_way='B' then sale_amt else 0 end),
giv_qty =  sum(case when sale_way='C' then sale_qty else 0 end),
giv_amt = sum(case when sale_way='C' then sale_amt else 0 end)
  into #t
  from pos_t_saleflow 
 where oper_date between @adt_from and @adt_to
   and branch_no = @branch_no
 group by branch_no, item_no,convert(char(10), oper_date, 120)

update pos_daysum set 
sale_qty =0,
ret_qty = 0,
giv_qty = 0,
sale_amt = 0,
ret_amt = 0,
giv_amt = 0
 where branch_no = @branch_no
   and oper_date between @adt_from and @adt_to

update pos_daysum set 
sale_qty = b.sale_qty,
ret_qty = b.ret_qty,
sale_amt = b.sale_amt,
ret_amt = b.ret_amt,
giv_qty = b.giv_qty,
giv_amt = b.giv_amt
  from #t b
 where pos_daysum.branch_no = b.branch_no
   and pos_daysum.item_no = b.item_no
   and pos_daysum.oper_date = b.oper_date


delete pos_casher_daysum where branch_no = @branch_no and oper_date between @adt_from and @adt_to
insert  pos_casher_daysum (oper_date, casher_no, branch_no, sale_amt, real_amt, 
                   sale_way, pay_way, coin_no, oper_type, other1, other2, other3, sheet_count, barcode_count) 
select oper_date = convert(varchar(10), oper_date, 120), oper_id, branch_no, 
sale_amt = sum(case when flow_id = 1 then sale_amt else 0 end),
real_amt = sum(case when pay_Way = 'A' and sale_Way = 'D' then -pay_amt else pay_amt end),
sale_way = (case when pay_Way = 'A' and sale_Way = 'D' then 'A' else sale_way end), pay_way,
coin_no, '0', null, null, null, sheet_count = count(distinct flow_no), barcode_count = count(com_no)
  from pos_t_payflow
 where  branch_no = @branch_no and oper_date between @adt_from and @adt_to
group by convert(varchar(10), oper_date, 120), oper_id, branch_no,
(case when pay_Way = 'A' and sale_Way = 'D' then 'A' else sale_way end), pay_way, coin_no

go

--exec pr_settle_posdaysum
go




 推荐知识

 历史版本

修改日期 修改人 备注
2022-04-06 14:58:47[当前版本] 吴翔宇 格式调整
2020-06-22 17:42:42 吴翔宇 20200622

慧邦知识分享平台 - free.V4.3.0-439 - 免费版