alter proc proc_fifo_outallocation
as 
begin
declare @id bigint,@inid bigint,@outid bigint,@projectid bigint,@materialid bigint,@priceid bigint,@type varchar(1),@outtype varchar(1),@getDate varchar(20),@createtime datetime,@employee bigint,@re varchar(1000)
declare @incount decimal(18,2),@outcount decimal(18,2),@remainnumber decimal(18,2),@leavecount decimal(18,2),@temp_count decimal(18,2),@allocationinid bigint
declare c_out cursor for
select id,allocationinid,type,createtime,employee,re,projectid,materialid,thiscount from v_fifo_out order by createtimeopen c_out
fetch NEXT from c_out into @outid,@allocationinid,@outtype,@createtime,@employee,@re,@projectid,@materialid,@outcount
WHILE @@FETCH_STATUS = 0 
begin
set @temp_count = 0
while (@temp_count < @outcount)
begin 
if (exists(select cast(remainnumber as decimal(18,2)) from v_fifo_in where cast(remainnumber as decimal(18,2))> 0 and materialid = @materialid and projectid = @projectid))
begin 
select top 1 @id = id,@type = type,@remainnumber = cast(remainnumber as decimal(18,2)),@inid=id,@priceid=price from v_fifo_in where cast(remainnumber as decimal(18,2))> 0 and materialid = @materialid and projectid = @projectid order by createtime
set @leavecount = @outcount  - @temp_count 
if (@remainnumber - @leavecount >= 0)
begin
insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@leavecount)
if @type='1'
update t_fn_material_warehouse set remainnumber = @remainnumber - @leavecount where id = @id
if @type='2'
update t_fn_orderin_detail set remainnumber = @remainnumber - @leavecount where id = @id
if @type='3'
update t_fifo_out_allocationin set remainnumber = @remainnumber - @leavecount where id = @id
if @type='4'
update t_fn_backwarehouse_detail set remainnumber = @remainnumber - @leavecount where id = @id
if (@outtype='1')
begin
insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price) values(@employee,@createtime,@re,@allocationinid,@leavecount,@materialid,@priceid)
end
set @temp_count = @temp_count + @leavecount
end
else 
begin
insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@remainnumber)
if @type ='1'
update t_fn_material_warehouse set remainnumber = 0.00 where id = @id
if @type ='2'
update t_fn_orderin_detail set remainnumber = 0.00 where id = @id
if @type='3'
update t_fifo_out_allocationin set remainnumber = 0.00 where id = @id
if @type='4'
update t_fn_backwarehouse_detail set remainnumber = 0.00 where id = @id
if (@outtype = '1')
begin
insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price)
values(@employee,@createtime,@re,@allocationinid,@remainnumber,@materialid,@priceid)
end
set @temp_count = @temp_count + @remainnumber  
end
end 

else 
begin 
select top 1 @id = id,@type = type,@incount = thiscount,@inid=id,@priceid=price from v_fifo_in where remainnumber is null and  materialid = @materialid and projectid = @projectid order by createtime
set @leavecount = @outcount  - @temp_count
if (@incount - @leavecount >=0)
begin
insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@leavecount)
if @type ='1'
update t_fn_material_warehouse set remainnumber = @incount - @leavecount where id = @id
if @type ='2'
update t_fn_orderin_detail set remainnumber = @incount - @leavecount where id = @id
if @type='3'
update t_fifo_out_allocationin set remainnumber = @incount - @leavecount where id = @id
if @type='4'
update t_fn_backwarehouse_detail set remainnumber = @incount - @leavecount where id = @id
if (@outtype = '1')
begin
insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price)
values(@employee,@createtime,@re,@allocationinid,@leavecount,@materialid,@priceid)
end
set @temp_count = @temp_count + @leavecount
end 
else
begin 
insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@incount)
if @type ='1'
update t_fn_material_warehouse set remainnumber = 0.00 where id = @id
if @type ='2'
update t_fn_orderin_detail set remainnumber = 0.00 where id = @id
if @type='3'
update t_fifo_out_allocationin set remainnumber = 0.00 where id = @id
if @type='4'
update t_fn_backwarehouse_detail set remainnumber = 0.00 where id = @id
if (@outtype = '1')
begin
insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price)
values(@employee,@createtime,@re,@allocationinid,@incount,@materialid,@priceid)
end
set @temp_count = @temp_count + @incount
end 
end 
end
fetch NEXT from c_out into @outid,@allocationinid,@outtype,@createtime,@employee,@re,@projectid,@materialid,@outcount
end
close c_out
deallocate c_out
end

解决方案 »

  1.   

    alter proc proc_fifo_outallocation 
    as 
    begin 
    declare @id bigint,@inid bigint,@outid bigint,@projectid bigint,@materialid bigint,@priceid bigint,@type varchar(1),@outtype varchar(1),@getDate varchar(20),@createtime datetime,@employee bigint,@re varchar(1000) 
    declare @incount decimal(18,2),@outcount decimal(18,2),@remainnumber decimal(18,2),@leavecount decimal(18,2),@temp_count decimal(18,2),@allocationinid bigint 
    declare c_out cursor for 
    select id,allocationinid,type,createtime,employee,re,projectid,materialid,thiscount from v_fifo_out order by createtime open c_out 
    fetch NEXT from c_out into @outid,@allocationinid,@outtype,@createtime,@employee,@re,@projectid,@materialid,@outcount 
    WHILE @@FETCH_STATUS = 0 
    begin 
    set @temp_count = 0 
    while (@temp_count < @outcount) 
    begin 
    if (exists(select cast(remainnumber as decimal(18,2)) from v_fifo_in where cast(remainnumber as decimal(18,2))> 0 and materialid = @materialid and projectid = @projectid)) 
    begin 
    select top 1 @id = id,@type = type,@remainnumber = cast(remainnumber as decimal(18,2)),@inid=id,@priceid=price from v_fifo_in where cast(remainnumber as decimal(18,2))> 0 and materialid = @materialid and projectid = @projectid order by createtime 
    set @leavecount = @outcount  - @temp_count 
    if (@remainnumber - @leavecount >= 0) 
    begin 
    insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@leavecount) 
    if @type='1' 
    update t_fn_material_warehouse set remainnumber = @remainnumber - @leavecount where id = @id 
    if @type='2' 
    update t_fn_orderin_detail set remainnumber = @remainnumber - @leavecount where id = @id 
    if @type='3' 
    update t_fifo_out_allocationin set remainnumber = @remainnumber - @leavecount where id = @id 
    if @type='4' 
    update t_fn_backwarehouse_detail set remainnumber = @remainnumber - @leavecount where id = @id 
    if (@outtype='1') 
    begin 
    insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price) values(@employee,@createtime,@re,@allocationinid,@leavecount,@materialid,@priceid) 
    end 
    set @temp_count = @temp_count + @leavecount 
    end 
    else 
    begin 
    insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@remainnumber) 
    if @type ='1' 
    update t_fn_material_warehouse set remainnumber = 0.00 where id = @id 
    if @type ='2' 
    update t_fn_orderin_detail set remainnumber = 0.00 where id = @id 
    if @type='3' 
    update t_fifo_out_allocationin set remainnumber = 0.00 where id = @id 
    if @type='4' 
    update t_fn_backwarehouse_detail set remainnumber = 0.00 where id = @id 
    if (@outtype = '1') 
    begin 
    insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price) 
    values(@employee,@createtime,@re,@allocationinid,@remainnumber,@materialid,@priceid) 
    end 
    set @temp_count = @temp_count + @remainnumber 
    end 
    end else 
    begin 
    select top 1 @id = id,@type = type,@incount = thiscount,@inid=id,@priceid=price from v_fifo_in where remainnumber is null and  materialid = @materialid and projectid = @projectid order by createtime 
    set @leavecount = @outcount  - @temp_count 
    if (@incount - @leavecount >=0) 
    begin 
    insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@leavecount) 
    if @type ='1' 
    update t_fn_material_warehouse set remainnumber = @incount - @leavecount where id = @id 
    if @type ='2' 
    update t_fn_orderin_detail set remainnumber = @incount - @leavecount where id = @id 
    if @type='3' 
    update t_fifo_out_allocationin set remainnumber = @incount - @leavecount where id = @id 
    if @type='4' 
    update t_fn_backwarehouse_detail set remainnumber = @incount - @leavecount where id = @id 
    if (@outtype = '1') 
    begin 
    insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price) 
    values(@employee,@createtime,@re,@allocationinid,@leavecount,@materialid,@priceid) 
    end 
    set @temp_count = @temp_count + @leavecount 
    end 
    else 
    begin 
    insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@incount) 
    if @type ='1' 
    update t_fn_material_warehouse set remainnumber = 0.00 where id = @id 
    if @type ='2' 
    update t_fn_orderin_detail set remainnumber = 0.00 where id = @id 
    if @type='3' 
    update t_fifo_out_allocationin set remainnumber = 0.00 where id = @id 
    if @type='4' 
    update t_fn_backwarehouse_detail set remainnumber = 0.00 where id = @id 
    if (@outtype = '1') 
    begin 
    insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price) 
    values(@employee,@createtime,@re,@allocationinid,@incount,@materialid,@priceid) 
    end 
    set @temp_count = @temp_count + @incount 
    end 
    end 
    end 
    fetch NEXT from c_out into @outid,@allocationinid,@outtype,@createtime,@employee,@re,@projectid,@materialid,@outcount 
    end 
    close c_out 
    deallocate c_out 
    end 写的太乱了!帮你排一下版!
      

  2.   

    alter proc proc_fifo_outallocation
    as 
    begin
    declare @id bigint,@inid bigint,@outid bigint,@projectid bigint,@materialid bigint,@priceid bigint,@type varchar(1),@outtype varchar(1),@getDate varchar(20),@createtime datetime,@employee bigint,@re varchar(1000)
    declare @incount decimal(18,2),@outcount decimal(18,2),@remainnumber decimal(18,2),@leavecount decimal(18,2),@temp_count decimal(18,2),@allocationinid bigint
    declare c_out cursor for
    select id,allocationinid,type,createtime,employee,re,projectid,materialid,thiscount from v_fifo_out order by createtimeopen c_out
    fetch NEXT from c_out into @outid,@allocationinid,@outtype,@createtime,@employee,@re,@projectid,@materialid,@outcount
    WHILE @@FETCH_STATUS = 0 
    begin
    set @temp_count = 0
    while (@temp_count < @outcount)
    begin 
    if (exists(select cast(remainnumber as decimal(18,2)) from v_fifo_in where cast(remainnumber as decimal(18,2))> 0 and materialid = @materialid and projectid = @projectid))
    begin 
    select top 1 @id = id,@type = type,@remainnumber = cast(remainnumber as decimal(18,2)),@inid=id,@priceid=price from v_fifo_in where cast(remainnumber as decimal(18,2))> 0 and materialid = @materialid and projectid = @projectid order by createtime
    set @leavecount = @outcount  - @temp_count 
    if (@remainnumber - @leavecount >= 0)
    begin
    insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@leavecount)
    if @type='1'
    update t_fn_material_warehouse set remainnumber = @remainnumber - @leavecount where id = @id
    if @type='2'
    update t_fn_orderin_detail set remainnumber = @remainnumber - @leavecount where id = @id
    if @type='3'
    update t_fifo_out_allocationin set remainnumber = @remainnumber - @leavecount where id = @id
    if @type='4'
    update t_fn_backwarehouse_detail set remainnumber = @remainnumber - @leavecount where id = @id
    if (@outtype='1')
    begin
    insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price) values(@employee,@createtime,@re,@allocationinid,@leavecount,@materialid,@priceid)
    end
    set @temp_count = @temp_count + @leavecount
    end
    else 
    begin
    insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@remainnumber)
    if @type ='1'
    update t_fn_material_warehouse set remainnumber = 0.00 where id = @id
    if @type ='2'
    update t_fn_orderin_detail set remainnumber = 0.00 where id = @id
    if @type='3'
    update t_fifo_out_allocationin set remainnumber = 0.00 where id = @id
    if @type='4'
    update t_fn_backwarehouse_detail set remainnumber = 0.00 where id = @id
    if (@outtype = '1')
    begin
    insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price)
    values(@employee,@createtime,@re,@allocationinid,@remainnumber,@materialid,@priceid)
    end
    set @temp_count = @temp_count + @remainnumber  
    end
    end 

    else 
    begin 
    select top 1 @id = id,@type = type,@incount = thiscount,@inid=id,@priceid=price from v_fifo_in where remainnumber is null and  materialid = @materialid and projectid = @projectid order by createtime
    set @leavecount = @outcount  - @temp_count
    if (@incount - @leavecount >=0)
    begin
    insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@leavecount)
    if @type ='1'
    update t_fn_material_warehouse set remainnumber = @incount - @leavecount where id = @id
    if @type ='2'
    update t_fn_orderin_detail set remainnumber = @incount - @leavecount where id = @id
    if @type='3'
    update t_fifo_out_allocationin set remainnumber = @incount - @leavecount where id = @id
    if @type='4'
    update t_fn_backwarehouse_detail set remainnumber = @incount - @leavecount where id = @id
    if (@outtype = '1')
    begin
    insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price)
    values(@employee,@createtime,@re,@allocationinid,@leavecount,@materialid,@priceid)
    end
    set @temp_count = @temp_count + @leavecount
    end 
    else
    begin 
    insert into t_fifo_out_materialdetail(createtime,inid,outid,priceid,count) values(@createtime,@inid,@outid,@priceid,@incount)
    if @type ='1'
    update t_fn_material_warehouse set remainnumber = 0.00 where id = @id
    if @type ='2'
    update t_fn_orderin_detail set remainnumber = 0.00 where id = @id
    if @type='3'
    update t_fifo_out_allocationin set remainnumber = 0.00 where id = @id
    if @type='4'
    update t_fn_backwarehouse_detail set remainnumber = 0.00 where id = @id
    if (@outtype = '1')
    begin
    insert into t_fifo_out_allocationin(employee,createtime,re,allocationinid,thiscount,materialid,price)
    values(@employee,@createtime,@re,@allocationinid,@incount,@materialid,@priceid)
    end
    set @temp_count = @temp_count + @incount
    end 
    end 
    end
    fetch NEXT from c_out into @outid,@allocationinid,@outtype,@createtime,@employee,@re,@projectid,@materialid,@outcount
    end
    close c_out
    deallocate c_out
    end
      

  3.   

    如果永远WHILE (@temp_count < @outcount)成立就会死循环,要看你的数据查remainnumber 或thiscount
      

  4.   

    while条件满足会跳出来 要不要用break
      

  5.   

    楼主仔细看看下面的东西,问题就出在这
    set @temp_count = 0 
    while (@temp_count < @outcount) 
    begin
    .......
      set @leavecount = @outcount  - @temp_count 
      if (@remainnumber - @leavecount >= 0) 
       begin
      set @temp_count = @temp_count + @leavecount 
       end
    end
    else
    .........楼主的判断条件在某种程度上,恒等。
    可不一直执行吗
      

  6.   

    你的过程中没有while何来死循环哟,只有可能你的游标数据记录太多,占用了大量的SQL资源假死了
      

  7.   


    ALTER PROC proc_fifo_outallocation
    AS 
        BEGIN 
            DECLARE @id BIGINT,
                @inid BIGINT,
                @outid BIGINT,
                @projectid BIGINT,
                @materialid BIGINT,
                @priceid BIGINT,
                @type VARCHAR(1),
                @outtype VARCHAR(1),
                @getDate VARCHAR(20),
                @createtime DATETIME,
                @employee BIGINT,
                @re VARCHAR(1000) 
            DECLARE @incount DECIMAL(18, 2),
                @outcount DECIMAL(18, 2),
                @remainnumber DECIMAL(18, 2),
                @leavecount DECIMAL(18, 2),
                @temp_count DECIMAL(18, 2),
                @allocationinid BIGINT 
            DECLARE c_out CURSOR
                FOR SELECT  id,
                            allocationinid,
                            type,
                            createtime,
                            employee,
                            re,
                            projectid,
                            materialid,
                            thiscount
                    FROM    v_fifo_out
                    ORDER BY createtime         OPEN c_out 
            FETCH NEXT FROM c_out INTO @outid, @allocationinid, @outtype,
                @createtime, @employee, @re, @projectid, @materialid,
                @outcount 
            WHILE @@FETCH_STATUS = 0 
                BEGIN 
                    SET @temp_count = 0 
                    WHILE ( @temp_count < @outcount ) 
                        BEGIN 
                            IF ( EXISTS ( SELECT    CAST(remainnumber AS DECIMAL(18, 2))
                                          FROM      v_fifo_in
                                          WHERE     CAST(remainnumber AS DECIMAL(18, 2)) > 0
                                                    AND materialid = @materialid
                                                    AND projectid = @projectid ) ) 
                                BEGIN 
                                    SELECT TOP 1
                                            @id = id,
                                            @type = type,
                                            @remainnumber = CAST(remainnumber AS DECIMAL(18, 2)),
                                            @inid = id,
                                            @priceid = price
                                    FROM    v_fifo_in
                                    WHERE   CAST(remainnumber AS DECIMAL(18, 2)) > 0
                                            AND materialid = @materialid
                                            AND projectid = @projectid
                                    ORDER BY createtime 
                                    SET @leavecount = @outcount - @temp_count 
                                    IF ( @remainnumber - @leavecount >= 0 ) 
                                        BEGIN 
                                            INSERT  INTO t_fifo_out_materialdetail
                                                    (
                                                      createtime,
                                                      inid,
                                                      outid,
                                                      priceid,
                                                      count
                                                    )
                                            VALUES  (
                                                      @createtime,
                                                      @inid,
                                                      @outid,
                                                      @priceid,
                                                      @leavecount
                                                    ) 
                                            IF @type = '1' 
                                                UPDATE  t_fn_material_warehouse
                                                SET     remainnumber = @remainnumber
                                                        - @leavecount
                                                WHERE   id = @id 
                                            IF @type = '2' 
                                                UPDATE  t_fn_orderin_detail
                                                SET     remainnumber = @remainnumber
                                                        - @leavecount
                                                WHERE   id = @id 
                                            IF @type = '3' 
                                                UPDATE  t_fifo_out_allocationin
                                                SET     remainnumber = @remainnumber
                                                        - @leavecount
                                                WHERE   id = @id 
                                            IF @type = '4' 
                                                UPDATE  t_fn_backwarehouse_detail
                                                SET     remainnumber = @remainnumber
                                                        - @leavecount
                                                WHERE   id = @id 
                                            IF ( @outtype = '1' ) 
                                                BEGIN 
                                                    INSERT  INTO t_fifo_out_allocationin
                                                            (
                                                              employee,
                                                              createtime,
                                                              re,
                                                              allocationinid,
                                                              thiscount,
                                                              materialid,
                                                              price
                                                            )
                                                    VALUES  (
                                                              @employee,
                                                              @createtime,
                                                              @re,
                                                              @allocationinid,
                                                              @leavecount,
                                                              @materialid,
                                                              @priceid
                                                            ) 
                                                END 
                                            SET @temp_count = @temp_count
                                                + @leavecount 
                                        END 
                                    ELSE 
                                        BEGIN 
                                            INSERT  INTO t_fifo_out_materialdetail
                                                    (
                                                      createtime,
                                                      inid,
                                                      outid,
                                                      priceid,
                                                      count
                                                    )
                                            VALUES  (
                                                      @createtime,
                                                      @inid,
                                                      @outid,
                                                      @priceid,
                                                      @remainnumber
                                                    ) 
                                            IF @type = '1' 
                                                UPDATE  t_fn_material_warehouse
                                                SET     remainnumber = 0.00
                                                WHERE   id = @id 
                                            IF @type = '2' 
                                                UPDATE  t_fn_orderin_detail
                                                SET     remainnumber = 0.00
                                                WHERE   id = @id 
                                            IF @type = '3' 
                                                UPDATE  t_fifo_out_allocationin
                                                SET     remainnumber = 0.00
                                                WHERE   id = @id 
                                            IF @type = '4' 
                                                UPDATE  t_fn_backwarehouse_detail
                                                SET     remainnumber = 0.00
                                                WHERE   id = @id 
                                            IF ( @outtype = '1' ) 
                                                BEGIN 
                                                    INSERT  INTO t_fifo_out_allocationin
                                                            (
                                                              employee,
                                                              createtime,
                                                              re,
                                                              allocationinid,
      

  8.   

                                                              thiscount,
                                                              materialid,
                                                              price
                                                            )
                                                    VALUES  (
                                                              @employee,
                                                              @createtime,
                                                              @re,
                                                              @allocationinid,
                                                              @remainnumber,
                                                              @materialid,
                                                              @priceid
                                                            ) 
                                                END 
                                            SET @temp_count = @temp_count
                                                + @remainnumber 
                                        END 
                                END                         ELSE 
                                BEGIN 
                                    SELECT TOP 1
                                            @id = id,
                                            @type = type,
                                            @incount = thiscount,
                                            @inid = id,
                                            @priceid = price
                                    FROM    v_fifo_in
                                    WHERE   remainnumber IS NULL
                                            AND materialid = @materialid
                                            AND projectid = @projectid
                                    ORDER BY createtime 
                                    SET @leavecount = @outcount - @temp_count 
                                    IF ( @incount - @leavecount >= 0 ) 
                                        BEGIN 
                                            INSERT  INTO t_fifo_out_materialdetail
                                                    (
                                                      createtime,
                                                      inid,
                                                      outid,
                                                      priceid,
                                                      count
                                                    )
                                            VALUES  (
                                                      @createtime,
                                                      @inid,
                                                      @outid,
                                                      @priceid,
                                                      @leavecount
                                                    ) 
                                            IF @type = '1' 
                                                UPDATE  t_fn_material_warehouse
                                                SET     remainnumber = @incount
                                                        - @leavecount
                                                WHERE   id = @id 
                                            IF @type = '2' 
                                                UPDATE  t_fn_orderin_detail
                                                SET     remainnumber = @incount
                                                        - @leavecount
                                                WHERE   id = @id 
                                            IF @type = '3' 
                                                UPDATE  t_fifo_out_allocationin
                                                SET     remainnumber = @incount
                                                        - @leavecount
                                                WHERE   id = @id 
                                            IF @type = '4' 
                                                UPDATE  t_fn_backwarehouse_detail
                                                SET     remainnumber = @incount
                                                        - @leavecount
                                                WHERE   id = @id 
                                            IF ( @outtype = '1' ) 
                                                BEGIN 
                                                    INSERT  INTO t_fifo_out_allocationin
                                                            (
                                                              employee,
                                                              createtime,
                                                              re,
                                                              allocationinid,
                                                              thiscount,
                                                              materialid,
                                                              price
                                                            )
                                                    VALUES  (
                                                              @employee,
                                                              @createtime,
                                                              @re,
                                                              @allocationinid,
                                                              @leavecount,
                                                              @materialid,
                                                              @priceid
                                                            ) 
                                                END 
                                            SET @temp_count = @temp_count
                                                + @leavecount 
                                        END 
                                    ELSE 
                                        BEGIN 
                                            INSERT  INTO t_fifo_out_materialdetail
                                                    (
                                                      createtime,
                                                      inid,
                                                      outid,
                                                      priceid,
                                                      count
                                                    )
                                            VALUES  (
                                                      @createtime,
                                                      @inid,
                                                      @outid,
                                                      @priceid,
                                                      @incount
                                                    ) 
                                            IF @type = '1' 
                                                UPDATE  t_fn_material_warehouse
                                                SET     remainnumber = 0.00
                                                WHERE   id = @id 
                                            IF @type = '2' 
                                                UPDATE  t_fn_orderin_detail
                                                SET     remainnumber = 0.00
                                                WHERE   id = @id 
                                            IF @type = '3' 
                                                UPDATE  t_fifo_out_allocationin
                                                SET     remainnumber = 0.00
                                                WHERE   id = @id 
                                            IF @type = '4' 
                                                UPDATE  t_fn_backwarehouse_detail
                                                SET     remainnumber = 0.00
                                                WHERE   id = @id 
                                            IF ( @outtype = '1' ) 
                                                BEGIN 
                                                    INSERT  INTO t_fifo_out_allocationin
                                                            (
                                                              employee,
                                                              createtime,
                                                              re,
                                                              allocationinid,
                                                              thiscount,
                                                              materialid,
                                                              price
                                                            )
                                                    VALUES  (
                                                              @employee,
                                                              @createtime,
                                                              @re,
                                                              @allocationinid,
                                                              @incount,
                                                              @materialid,
                                                              @priceid
                                                            ) 
                                                END 
                                            SET @temp_count = @temp_count
                                                + @incount 
                                        END 
                                END 
                        END 
                    FETCH NEXT FROM c_out INTO @outid, @allocationinid, @outtype,
                        @createtime, @employee, @re, @projectid, @materialid,
                        @outcount 
                END 
            CLOSE c_out 
            DEALLOCATE c_out 
        END