已经生成的月底库存表 stock_month_list part_no ,end_qty和采购明细表 material_delivery_list part_no,delivery_date,standard_qty(采购数量),standard_price

解决方案 »

  1.   

    请参考
    http://community.csdn.net/Expert/topic/4704/4704065.xml?temp=.3512537
      

  2.   

    不用游标作循环的例子,你卡伊参考一下
    SET NOCOUNT ON
    DECLARE @iNextRowId int,@iCurrentRowId int,@iLoopControl int,@ID int
    -- Initialize variables!
    SELECT @iLoopControl = 1
    SELECT @iNextRowId = MIN(id) FROM tblA
    -- Make sure the table has data.
    IF ISNULL(@iNextRowId,0) = 0
    BEGIN
          SELECT 'No data in found in table!'
          RETURN
    END
    -- Retrieve the first row
    SELECT @iCurrentRowId = id,@id = ID FROM tblA WHERE id = @iNextRowId
    -- start the main processing loop.
    WHILE @iLoopControl = 1
    BEGIN
         -- This is where you perform your detailed row-by-row
         -- processing.     
         -- Reset looping variables.  
        SELECT 'A'          
        SELECT   @iNextRowId = NULL            
        -- get the next iRowId
        SELECT   @iNextRowId = MIN(id)FROM tblA WHERE ID > @iCurrentRowId
        -- did we get a valid next row id?
        IF ISNULL(@iNextRowId,0) = 0
        BEGIN
          BREAK
        END
        -- get the next row.
        SELECT  @iCurrentRowId = ID,@ID = ID FROM tblA WHERE   ID = @iNextRowId            
    END
    RETURN
    ST NOCOUNT OFF
      

  3.   

    hyrongg(世道变得太快) 的方法没有用游标,但看起来也是一条条处理,会快一些吗?