IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[userfunc_745_zx]') AND type = 'P')
DROP PROCEDURE [dbo].[userfunc_745_zx]
GO
CREATE PROCEDURE userfunc_745_zx(@cmpid int,   @branchid int,  @userdpid int,  @useruid int,   @userotid int,  @usersecurity int,@ctgid int,@ctgid2 int,@objid bigint,@ordid int,@bcid1 int)
as
begin



    set nocount on ;
    delete from  order_267_2 where ord2_ordid = @ordid
    insert into order_267_2 (ord2_ordid,ord2_fordid,ord2_fbizid,ord2_tag,ord2_mdordid,
    ord2_rq,ord2_pp,ord2_xh,ord2_zdimei,ord2_jjmd,ord2_jjlx,ord2_sxfj,ord2_gz,ord2_wxlx,ord2_clff,ord2_bz)
    select @ordid,a.ord_id,260,2,a.ord_id,
    a.ord_date,a.ord_zdpp,a.ord_zdxh,a.ord_imei,a.ord_createdepart,a.ord_zdlx,a.ord_sxfj,a.ord_gzfl1j,a.ord_wxlx,a.ord_yjclff,a.ord_wxbz 
    from order_260 a , order_266 b, order_266_2 c
    where a.ord_bcid = @bcid1 and a.ord_dqzt = '待总部返厂装箱' 
    and a.ord_id = c.ord2_mdordid and c.ord2_fbizid = 260 and c.ord2_ordid = b.ord_id and c.ord2_zbqr = '是'
    and charindex('临',b.ord_no) = 0


end