0

我更改了以下程序以按部门显示项目库存。但是,这似乎并没有更新部门。我不确定程序有什么问题。有什么帮助吗?

ALTER PROCEDURE [dbo].[GetWHInventoryValue]
AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

      DECLARE @loccode CHAR(3)
      DECLARE @locationID CHAR(10)

      DELETE FROM DailySummaries
      WHERE  Item = 119;

      DECLARE activeLocations CURSOR FOR
        SELECT warehouseid,
               whcode
        FROM   warehouse
        WHERE  inactive != 'T';

      OPEN activeLocations

      FETCH next FROM activeLocations INTO @locationID, @loccode

      WHILE( @@FETCH_STATUS = 0 )
        BEGIN
            INSERT INTO DailySummaries
                        (Item,
                         Location,
                         Amount,
                         DepartmentID,
                         [Date])
            VALUES     (119,
                        @loccode,
                        0,
                        0,
                        GETDATE());

            DECLARE @whTotal NUMERIC(13, 2)
            DECLARE @itemID CHAR(10)
            DECLARE @itemCost NUMERIC(11, 2)
            DECLARE @departmentID CHAR(12)

            DECLARE whItems CURSOR FOR
              SELECT mst.masterid,
                     mst.replacementcost,
                     mv.inventorydepartmentid
              FROM   masterwh AS wh,
                     [master] AS mst,
                     masterview mv
              WHERE  mst.masterid = wh.masterid
                     AND wh.warehouseid = @locationid
                     AND mv.masterid = mst.masterid
                     AND mv.warehouseid = wh.warehouseid

            OPEN whItems;

            FETCH next FROM whItems INTO @itemID, @itemCost, @departmentID

            WHILE( @@FETCH_STATUS = 0 )
              BEGIN
                  DECLARE @itemQty NUMERIC(11, 2)

                  DECLARE itemQty CURSOR FOR
                    SELECT SUM(mw.qty)
                    FROM   masterwhqty mw,
                           masterview mv
                    WHERE  mw.warehouseid = @locationid
                           AND mw.masterid = @itemID
                           AND mw.qty > 0
                           AND mv.masterid = mw.masterid
                           AND mv.warehouseid = mw.warehouseid
                           AND mv.inventorydepartmentid = @departmentID;

                  OPEN itemQty;

                  FETCH next FROM itemQty INTO @itemQty;

                  UPDATE DailySummaries
                  SET    amount = amount + ( isnull(@itemQty, 0) * @itemCost ),
                         DepartmentID = @departmentID
                  WHERE  Location = @loccode
                         AND Item = 119
                         AND DepartmentID = @departmentID;

                  DEALLOCATE itemQty;

                  FETCH next FROM whItems INTO @itemID, @itemCost, @departmentID
              END

            DEALLOCATE whItems;

            FETCH next FROM activeLocations INTO @locationID, @loccode
        END

      DEALLOCATE activeLocations;
  END 
4

1 回答 1

3

这是您的更新代码:

UPDATE DailySummaries SET amount = amount + (isnull(@itemQty,0) * @itemCost), DepartmentID=@departmentID WHERE Location = @loccode AND Item = 119  and DepartmentID=@departmentID;

这里我只提取了相关部分:

SET DepartmentID = @departmentID WHERE DepartmentID = @departmentID;

您会注意到此类代码的更新吗?

于 2013-09-11T20:15:08.323 回答