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

  • SEARCH
  • Home
  • 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 276395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:54:52+00:00 2026-05-12T00:54:52+00:00

I think the answer to this is no going in, but I could use

  • 0

I think the answer to this is no going in, but I could use a sanity check.

I have a proc that returns 3 tables. Table1 has 23 columns. Table2 has 12 columns. Table3 has 2 columns. I need to run this proc and dump the results of Table1 into a temp table. I created a @table and then did this:

insert @myTable 
exec [myDb].dbo.[multitableProc] 'A', 'B', 'C', 100 

But when I do this the error is:

Insert Error: Column name or number of
supplied values does not match table
definition.

Which makes me think SQL is pretty damn confused about what I want to do. I’m positive the table has the correct number of columns, double checked that. The datatypes are correct.

In conclusion, I’m pretty sure this just isn’t possible, but someone here might have a trick. Changing the source proc is not allowed. I did see one similar question, but he was trying to do some union type stuff, not the same.

  • 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-12T00:54:52+00:00Added an answer on May 12, 2026 at 12:54 am

    The only way I can think of doing it is with a CLR stored procedure. Have the CLR sproc call the sproc that returns the three tables. Then, grab only the single table you want and return that from your CLR sproc. Insert the results of your CLR sproc into your @myTable. I think this will provide you with the extra level of indirection necessary to get rid of the column mismatch from the other two result sets.

    Okay, I created a greatly simplified version to test. I returned two result sets from a table, one with one column and one with two …

    DECLARE @myTable TABLE ( col1 varchar(50) )
    
    INSERT @myTable( col1 )
    EXEC TestTable
    

    Gets the correct result …

    Msg 213, Level 16, State 7, Procedure
    TestTable, Line 23 Column name or
    number of supplied values does not
    match table definition.

    I made this CLR sproc that only takes the first result set (the one with only one column) from my TestTable TSQL sproc and returns only that table …

    public partial class StoredProcedures
    {
        [Microsoft.SqlServer.Server.SqlProcedure]
        public static void FilterResult()
        {
            using (var conn = new SqlConnection("context connection = true"))
            {
                var retVal = new SqlDataRecord( new SqlMetaData("col1",
                                                SqlDbType.NVarChar, 50));
                conn.Open();
    
                var cmd = new SqlCommand("exec TestTable", conn);
    
                SqlContext.Pipe.SendResultsStart(retVal);
    
                using (var dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var tmpCol = dr.GetString(0);
                        retVal.SetString(0, tmpCol);
    
                        SqlContext.Pipe.SendResultsRow(retVal);
                    }
    
                    dr.Close();
                }
    
                SqlContext.Pipe.SendResultsEnd();
            }
        }
    };
    

    Then, I am able to execute …

    INSERT @myTable( col1 )
    EXEC TestFilter  -- note the CLR sproc here instead of the TSQL sproc
    

    … and all is happy …

    (2 row(s) affected)

    At the end of the day, it might be more trouble than it’s worth, but it does work as a proof of concept. (No warranty as to performance tho.)

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

Sidebar

Related Questions

I have searched this web looking for an answer, but it seems that this
I think I already know the answer to this but thought I would ask
I think there is a simple answer to this, but for some reason I
I think i already know the answer to this, but i cannot find anything
According to this answer , I can make C++ mode think that underscores are
Well I think I know the answer to this, but I would appreciate anybody
I think this is a simple question, but I can not find the answer
I am stumped on this homework problem. I think I have the right answer
I am sure there is a very simple answer to this question, I think
[see later answer for more] I think this is just a simple rails question,

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.