Search this insane blog:

Tuesday, April 20, 2010

loop through records

-- runningCaseTotal


DECLARE @rowcount INT,
@item_no VARCHAR(20),
@id INT -- identity key to track rows with
SET @rowcount = (SELECT COUNT(*) FROM dbo.production_availability_ready_not_ready)
-----------------------------
--UPDATE dbo.production_availability_ready_not_ready
--SET runningCaseTotal = NULL
-----------------------------

WHILE @rowcount>0
BEGIN
-------TESTING-----------------
--PRINT 'ROWCOUNT: ' + CONVERT(VARCHAR(20),@rowcount)
--SET @id = (SELECT TOP 1 id FROM dbo.production_availability_ready_not_ready WHERE runningCaseTotal IS null)
--PRINT '..processing @id ' + CONVERT(VARCHAR(20),@id)
--SET @item_no = (SELECT [Item No_] FROM dbo.production_availability_ready_not_ready WHERE id = @id)
--UPDATE dbo.production_availability_ready_not_ready SET runningCaseTotal = 0 WHERE id = @id
--PRINT 'item_no: ' + CONVERT(VARCHAR(20),@item_no)
--PRINT '---------'
-----------------------------




SET @rowcount = @rowcount-1;


END

No comments:

Post a Comment