按物控档领料倒扣时,判断是否最后一笔入库的条件的疑问,建议按如下修改。
DECLARE c_accept2sql1 CURSOR FORWARD_ONLY FOR
Select a.sheet_lot, c.sheet_type, c.cust_no , c.sheet_date,
a.sheet_sta, c.sheet_no,
a.dIf_flag, a.part_no, a.mpart_no,
a.unit_no, a.unit_rate,
a.sheet_qty , a.sheet_qty1, a.pur_lot,
obas_sheet_type.stk_sta As stk_sta1, obas_sheet_type.stkwh2_sta,
obas_sheet_type.sheet_kind, obas_sheet_type.sheet_attr,
c.org_no, c.create_date, c.user_no,
Case When (
Case When opur_pur2.pur_qty_check = '0'
Then opur_pur2.in_tempqty+
opur_pur2.in_qty +
opur_pur2.scrab_tempqty+
opur_pur2.scrab_qty-
opur_pur2.intl_tempqty-
opur_pur2.intl_qty-
opur_pur2.sheet_qty *(1-obas_part1.err_rate)
Else opur_pur2.scm_in_tempqty+
opur_pur2.scm_in_qty+
opur_pur2.scm_scrab_tempqty+
opur_pur2.scm_scrab_qty-
opur_pur2.scm_intl_tempqty-
opur_pur2.scm_intl_qty-
opur_pur2.scm_sheet_qty
End) >=0 and
not exists(select top 1 1
from oscm_accept_in2 ,oscm_accept_in1,obas_sheet_type
where oscm_accept_in2.sheet_no=oscm_accept_in1.sheet_no and
oscm_accept_in1.sheet_type=obas_sheet_type.sheet_type and
obas_sheet_type.sheet_kind in ('SCM04','SCM06','SCM07','SCM09','SCM11','SCM12') and
oscm_accept_in2.pur_lot=a.pur_lot and
oscm_accept_in1.sheet_date>c.sheet_date )--增加判断是否是最后一笔入库单 李顶立
Then '5'
Else '0' End
From oscm_accept_in2 As a,
@t_mo as d,
obas_sheet_type,
oscm_accept_in1 As c,
obas_sheet_type As b,
opur_pur1,opur_pur2 join obas_part1 on opur_pur2.part_no=obas_part1.part_no
Where a.sheet_lot=d.mo_lot and
a.sheet_no=c.sheet_no and
obas_sheet_type.sheet_type=c.sheet_type and
obas_sheet_type.sheet_kind in ('SCM04','SCM06','SCM07','SCM09','SCM11','SCM12') and
opur_pur2.sheet_lot=a.pur_lot and
opur_pur1.sheet_no=opur_pur2.sheet_no and
opur_pur1.sheet_type=b.sheet_type and
b.sheet_kind in ('SFC01','SUB03') and
isnull(b.sfcwhout_sw,'0')='0'