How can one iterate over stored procedure results from within another stored procedure…without cursors?

前端 未结 7 1862
半阙折子戏
半阙折子戏 2020-12-19 07:06

I\'m not sure if this is something I should do in T-SQL or not, and I\'m pretty sure using the word \'iterate\' was wrong in this context, since you should never iterate any

7条回答
  •  情书的邮戳
    2020-12-19 08:05

    This may not be the most efficient, but I would create a temp table to hold the results of the stored proc and then use that in a join against the target table. For example:

    CREATE TABLE #t (uniqueid int)
    INSERT INTO #t EXEC p_YourStoredProc
    
    UPDATE TargetTable 
    SET a.FlagColumn = 1
    FROM TargetTable a JOIN #t b 
        ON a.uniqueid = b.uniqueid
    
    DROP TABLE #t
    

提交回复
热议问题