Home Forums SQL Server 2008 T-SQL (SS2K8) How to execute stored proc iin a loop for a date range RE: How to execute stored proc iin a loop for a date range

  • Thanks for responding. I need to execute the stored procedure in batches either through a while loop or some kind of table with identity column, but I don't know what is the best or most efficient way to do it. I cannot modify the stored proc, I can only call it with a date range given. The date range is big, and I don't want to update all the records in that one date range. So I am asking is there a way for me to execute the stored procedure in batches. Just like you would with an update or insert statement, but rather it is a stored procedure, but with the stored proc, I have to somehow link the batches to the stored procedure in order to update correctly within the date range given.

    This is just an example of what I am trying to do

    while @mindate (or @minid) < @maxdate (or @maxId)

    begin

    exec sproc_updatesomething @minid

    set @minid = @mind + 1

    end

    something like that. hope this explains what I am trying to do. Maybe I need to split the date into week or month or something.