Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 254151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:49:21+00:00 2026-05-11T21:49:21+00:00

I have a SQL Server 2005 stored proc which returns two result sets which

  • 0

I have a SQL Server 2005 stored proc which returns two result sets which are different in schema.

Another stored proc executes it as an Insert-Exec. However I need to insert the first result set, not the last one. What’s a way to do this?

I can create a new stored proc which is a copy of the first one which returns just the result set I want but I wanted to know if I can use the existing one which returns two.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:49:21+00:00Added an answer on May 11, 2026 at 9:49 pm

    Actually, INSERT..EXEC will try to insert BOTH datasets into the table. If the column counts match and the datatype can be implicitly converted, then you will actually get both.

    Otherwise, it will always fail because there is no way to only get one of the resultsets.

    The solution to this problem is to extract the functionality that you want from the called procedure and incorporate it into the (formerly) calling procedure. And remind yourself while doing it that “SQL is not like client code: redundant code is more acceptable than redundant data”.

    In case this was not clear above, let me delineate the facts and options available to anyone in this situation:

    1) If the two result sets returned are compatible, then you can get both in the same table with the INSERT and try to remove the ones that you do not want.

    2) If the two result sets are incompatible then INSERT..EXEC cannot be made to work.

    3) You can copy the code out of the called procedure and re-use it in the caller, and deal with the cost of dual-editing maintenance.

    4) You can change the called procedure to work more compatibly with your other procedures.

    Thats it. Those are your choices in T-SQL for this situation. There are some additional tricks that you can play with SQLCLR or client code but they will involve going about this a little bit differently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 202k
  • Answers 202k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I assume there can be only one result from that… May 12, 2026 at 8:26 pm
  • Editorial Team
    Editorial Team added an answer For WPF (itself a GUI API) there's Expression Blend, which… May 12, 2026 at 8:26 pm
  • Editorial Team
    Editorial Team added an answer You do have to close client connections after you finish… May 12, 2026 at 8:26 pm

Related Questions

I've had this problem a few times and solved it the same way. But
I'm trying to determine the relative performance of two different queries and have two
So here is a bit of a strange one... I have a stored proc
I have an asp.net web site which will send several ExecuteNonQuery() statements (stored proc)

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.