Wednesday, 11 September 2013

Alter Procedure does not update departmentID

Alter Procedure does not update departmentID

I altered the following procedure to display item inventory by department.
However, this does not seem to be updating the department. I am unsure
what is wrong with the procedure. Any help?
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

No comments:

Post a Comment