Is there another way that I could do the following query
SELECT @MinID = MIN(ID), @MaxID = MAX(ID)
FROM #stp
WHILE (@MinID <= @MaxID AND IsNull(@MaxID, 0) > 0)
BEGIN
SELECT @result_mstr_id = result_mstr_id
FROM #stp
WHERE ID = @MinID
EXECUTE @err = f_rslm_publish @result_mstr_id
UPDATE dbo.results
SET result_stat_cd = CASE result_stat_cd
WHEN 'IP' THEN 'C'
WHEN 'IS' THEN 'S'
ELSE result_stat_cd
END
WHERE result_mstr_id = @result_mstr_id
SELECT @MinID = @MinID + 1
END
Its the typical loop being fed by a counter but could I re-write this to be one query?
You can’t. If you need to execute the stored procedure
f_rslm_publishfor every ID in the table#stp, then you’ll need to use aWHILEloop or a cursor.Unless of course you can change the definition of the stored procedure
f_rslm_publish, in which case it very well may be possible to rewrite it to accept a range of ID values (and possibly without also addingWHILEloops to the stored procedure code).