How to save results of a procedure with more than one result set

  • Comments posted to this topic are about the item How to save results of a procedure with more than one result set

  • You can use the context connection to get the server name. Create a non-context connection from that information and then use bulk copy.

  • For each table name: if we already have such a table in the database, drop it ...

    ... and say goodbye to a concurrent process (if any) 🙂

    Not so good, I would say.

  • vk-kirov (9/6/2012)


    For each table name: if we already have such a table in the database, drop it ...

    ... and say goodbye to a concurrent process (if any) 🙂

    Not so good, I would say.

    An improvement might be to limit the target tables to temporary tables. That's the scenario I would expect this sort of idea to be used with. On the other hand, we also have MARS...but I guess that's another story.

  • SQL Kiwi (9/6/2012)


    vk-kirov (9/6/2012)


    For each table name: if we already have such a table in the database, drop it ...

    ... and say goodbye to a concurrent process (if any) 🙂

    Not so good, I would say.

    An improvement might be to limit the target tables to temporary tables. That's the scenario I would expect this sort of idea to be used with. On the other hand, we also have MARS...but I guess that's another story.

    Temporary tables could be a good improvement if we only need resulting tables in same session. It all depends on your requirements.

    If we don't need to drop tables at all, we can just remove corresponding code from the procedure. In my case, corresponding tables didn't exist before procedure execution, and creating those tables by hands could be huge waste of time because I had lots of stored procedures to process.

  • Pavel Sinkevich (9/6/2012)


    Temporary tables could be a good improvement if we only need resulting tables in same session.

    Global temporary tables e.g. ##Fish 🙂

  • Nice - a potential SQL injection vulnerability right inside your database! 😛

  • That seems like a lot of work, when you could modify the original stored procedure to save the multiple result sets to a temp table and then return them all as one result set. Of course, there might be a reason that you can't update the procedure, but it seems like that would be the preferable course.

  • bens4lsu (9/6/2012)


    That seems like a lot of work, when you could modify the original stored procedure to save the multiple result sets to a temp table and then return them all as one result set. Of course, there might be a reason that you can't update the procedure, but it seems like that would be the preferable course.

    I was wondering this too and since the solution requires creating a new stored procedure anyways why not just do it all in the same stored procedure?

  • ZZartin (9/6/2012)


    bens4lsu (9/6/2012)


    That seems like a lot of work, when you could modify the original stored procedure to save the multiple result sets to a temp table and then return them all as one result set. Of course, there might be a reason that you can't update the procedure, but it seems like that would be the preferable course.

    I was wondering this too and since the solution requires creating a new stored procedure anyways why not just do it all in the same stored procedure?

    In my case - because I had limited access to the database and couldn't modify any legacy code.

    As I noted in the article, this procedure can be used for ETL process from poorly designed databases, were we have lots of multiple result set procedures, and we don't want to modify each of them.

  • For those using 'Legacy' systems--back in the day of VBA and DAO--one could just use a DAO recordset based on a pass-thru query calling the SP, then use the .NextRecordset method to iterate through the result sets.

    --Jim

Viewing 11 posts - 1 through 10 (of 10 total)

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