and batch = #{batch}
and (batch IS NULL OR batch = '')
INSERT INTO
asr_loc_detl(loc_no,zpallet,barcode,batch,anfme,matnr,maktx,unit,specs,model,color,manu,sku,brand
,origin,item_num,manu_date,weight,volume,length,modi_time,modi_user,appe_time,appe_user)
VALUES
(
#{item.locNo},
#{item.zpallet},
#{item.barcode},
#{item.batch},
#{item.anfme},
#{item.matnr},
#{item.maktx},
#{item.unit},
#{item.specs},
#{item.model},
#{item.color},
#{item.manu},
#{item.sku},
#{item.brand},
#{item.origin},
#{item.itemNum},
#{item.manuDate},
#{item.weight},
#{item.volume},
#{item.length},
#{item.modiTime},
#{item.modiUser},
#{item.appeTime},
#{item.appeUser}
)
delete from asr_loc_detl
where 1=1
and loc_no = #{locNo}
and matnr = #{matnr}
update asr_loc_detl
set anfme = #{anfme}
, modi_time = getdate()
where 1=1
and loc_no = #{locNo}
and matnr = #{matnr}
delete from asr_loc_detl
where 1=1
and loc_no = #{locNo}
and model = #{model}
update asr_loc_detl
set anfme = #{anfme}
, modi_time = getdate()
where 1=1
and loc_no = #{locNo}
and model = #{model}
and a.loc_no like '%' + #{loc_no} + '%'
and a.matnr like '%' + #{matnr} + '%'
and a.maktx like '%' + #{maktx} + '%'
and a.anfme like '%' + #{anfme} + '%'
and a.modi_time between #{startTime} and #{endTime}
and b.crn_no=#{crnNo}
and a.batch like '%' + #{batch} + '%'
and a.specs like '%' + #{specs} + '%'
and a.brand like '%' + #{brand} + '%'
and a.model like '%' + #{model} + '%'
and a.unit like '%' + #{unit} + '%'
UPDATE a
SET a.matnr=b.matnr,
a.specs=b.specs,
a.maktx=b.maktx,
a.unit=b.unit
FROM asr_loc_detl a
INNER JOIN man_mat b ON a.matnr=#{matnrOld} AND b.matnr=#{matnr};
update asr_loc_detl set dead_warn = #{status},modi_time = getdate() where loc_no = #{locNo}