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 8284213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:01:21+00:00 2026-06-08T11:01:21+00:00

This probably has been asked before, but I was unable to find a satisfying

  • 0

This probably has been asked before, but I was unable to find a satisfying answer.

I need to insert results of a stored procedure into a temporary table, something like:

INSERT INTO #TEMP EXEC MY_SP

I don’t know in advance how many columns the SP will return, so I need to prepare my #TEMP table (via dynamic ALTER .. ADD commands) to add columns to match SP resultset.

Assumption is – SP accepts no parameters and number of columns is always the same. But how do I determine that number in pure TSQL outside of SP so I can store it for example into a variable?

  • 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-06-08T11:01:24+00:00Added an answer on June 8, 2026 at 11:01 am

    Tough one, especially if someone else is denying you the necessary permissions to run e.g. OPENROWSET.

    Have you considered unpacking/script the SP and add its contents directly to your T-SQL? In this way you can modify and adapt it however you may want.

    Otherwise, if you could explain more about the SP:

    • What does the SP do?
    • What kind of information does it output? One-N columns, – how many rows?
    • Is it slow/fast? (Could we perhaps use a brute-force [try-catch] approach)?
    • How does it determine the columns to output and how often does that change?
    • Can you pre-determine the columns in any way? (So that you may use an INSERT #temp EXEC sp_getData syntax).

    Best of luck!

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

Sidebar

Related Questions

This has probably been asked before on SO, but I was unable to find
This has probably been asked before but I couldn't find the answer to my
This has probably been asked before but I can't seem to find the answer.
This has probably been asked before, but I can't find a good way of
I know this has probably been asked before, but I can't find it with
I know this has probably been asked before but I can't find a specific
this has probably been asked before, but I haven't been able to find any
This probably has been asked before but all I can find are questions regarding
This has probably been asked before but I can't find it anywhere. I have
I know this has probably been asked before but I can't seem to find

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.