• A cursor certainly wouldn't be needed here; this could be accomplished with a temp table or CTE quite easily. You could do something like so:

    CREATE TABLE #Temp(Order# varchar(100))

    INSERT INTO #Temp(Order#)

    SELECT Order#

    FROM (table)

    WHERE Status = 'O'

    DELETE FROM (table)

    FROM (table)

    INNER JOIN #Temp

    ON (table).Order# = #Temp.Order#

    This will find any order numbers that have a status of O at some point, and delete anything having those order numbers from the table. As always, be certain you test this before going ahead with it!

    Also, if this is going to be deleting a large number of rows, you'll want to break up the delete into batches to avoid bloating your transaction log.

    There may well be a more efficient means of doing this, but it's the most to-the-point method I could think of.

    EDIT: Aha! Sean's method certainly works too, and would more than likely be a smoother setup for the deletion 🙂

    - 😀