CREATE PROC [dbo].[ZAIQ_Update_User]  
@II_Parentid nvarchar(50),          -- 父节点ID
@App_F_No  nvarchar(50), -- 报验号
@UserID  int, -- 用户ID
@AppUserID   int,     -- 审核人ID AS 
begin
declare @t table(ii_id int)
insert @t select ii_id from zaiq_iteminfo where ii_parentid =@II_Parentid
while @@rowcount > 0
insert @t select a.ii_id from zaiq_iteminfo a inner join @t as b
on a.ii_parentid = b.ii_id and a.ii_id not in(select ii_id from @t) 

update ZAIQ_Sample_Item set S_I_Leader=@UserID,S_I_AppLeader= @AppUserID
where II_ID in
(select II_ID from ZAIQ_Sample_Item 
where II_ID in (select II_ID from @t) and App_F_No=@App_F_No) and SI_AoriginNo=@AoriginNo
update ZAIQ_Sample_Item set S_I_Leader=@UserID,S_I_AppLeader= @AppUserID
where II_ID=@II_Parentid and App_F_No=@App_F_No and SI_AoriginNo=@AoriginNo
end 

解决方案 »

  1.   


    CREATE PROC [dbo].[ZAIQ_Update_User]   
    @II_Parentid nvarchar(50), -- 父节点ID
    @App_F_No nvarchar(50), -- 报验号
    @UserID int, -- 用户ID
    @AppUserID int, -- 审核人IDAS  
    begin
    declare @t table(ii_id int)
    insert @t select ii_id from zaiq_iteminfo where ii_parentid =@II_Parentid
    while @@rowcount > 0
    insert @t select a.ii_id from zaiq_iteminfo a inner join @t as b
    on a.ii_parentid = b.ii_id and a.ii_id not in(select ii_id from @t)  update ZAIQ_Sample_Item set S_I_Leader=@UserID,S_I_AppLeader= @AppUserID
    where II_ID in
    (select II_ID from ZAIQ_Sample_Item  
    where II_ID in (select II_ID from @t) and App_F_No=@App_F_No) and SI_AoriginNo=@AoriginNo
    update ZAIQ_Sample_Item set S_I_Leader=@UserID,S_I_AppLeader= @AppUserID
    where II_ID=@II_Parentid and App_F_No=@App_F_No and SI_AoriginNo=@AoriginNo 
    end 
    你想按什么条件删除,说详细点