Running an SP inside a select statement

  • Howdy all,

    in a new stored procedure, i want to so a 'select ID from table' to get all of the IDs in the table, and then run an existing SP for each ID. Seems simple enough, but then so am I.

    Thanks

  • Use the corsor or while loop to do this or

    you can use undocumented extended procedure xp_execresultset procedure to do this...

     

    MohammedU
    Microsoft SQL Server MVP

  • i'll give it a shot

    thanks

  • Why can't you rewrite the said sp to process more than one line at the same time??  Would be much simpler to do that way.

  • Re-write the called sp as a function, then modify the select statement to

    SELECT ID, dbo.fn_YourFunction(ID) ...

  • Potato, potâto.  That will still do row by row processing which is exactly the opposite of what sql server was optimisez for.

     

    What is so complexe in that procedure that sql server can't handle more than one row at the time? >>  Never seen that happen, it's usually our own limits or a business requirement (extremely rare).

  • it was more the limits of my sql knowledge. went a fully different route. thanks all

  • Can you post the final solution so that others may benefit from your work.

     

    TIA.

  • it wasn't really a solution per say, i just realised that looking at the problem in a different way eliminated it

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply