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コードです:

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 に答える