SQL Server Performance

Replacing Cursors

Discussion in 'SQL Server 2005 General Developer Questions' started by DStevensTN, Jun 5, 2006.

  1. DStevensTN New Member

    I have a task where I need to call about 7 stored procedures for each company in our database. The stored procs need to be called in a different order for each company based on a priority. I know how to handle this using embedded cursors, but I am very concerned this will take too long. Can anyone suggest how I can better perform this task?
  2. merrillaldrich New Member

    You can use a loop (it might or might not perform better, because it's basically doing the same thing as a fast-forward cursor):

    declare a table variable with an identity column

    insert into the table variable a list of the items to process

    set i = 1
    set end = max( identity column from the table variable )

    while i <= end

    -- do things using the ith item in the table variable

    set i = i + 1
  3. DStevensTN New Member

    Thanks I will give this a try

Share This Page