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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:45:15+00:00 2026-05-26T09:45:15+00:00

My Scenario I’m working on a database which will contain many details from various

  • 0

My Scenario

I’m working on a database which will contain many details from various Stored Procedures in different databases across the entire server. The information I’m attempting to gather now is, “What does the SP output?”

In searching I’ve found that the answer lies in OPENROWSET. My initial testing was successful and everything looked great. However, upon testing it with live SPs I ran into one major problem: It doesn’t play well with temp (#) tables.

For example:

If I were to take this SP:

CREATE PROCEDURE dbo.zzTempSP(@A INT, @B INT) AS
SELECT @A AS A, @B AS B

I can easily insert the output into a temp (##) table with the following code, then query tempdb’s sysobjects and produce a list of the columns and their data types:

IF OBJECT_ID('tempdb.dbo.##TempOutput','U') IS NOT NULL DROP TABLE ##TempOutput

DECLARE @sql VARCHAR(MAX)
SELECT @sql = 'SELECT * 
               INTO ##TempOutput
               FROM OPENROWSET(''SQLNCLI'', ''Server=' + 
        CONVERT(VARCHAR(100), SERVERPROPERTY('MachineName')) +
                             ';Trusted_Connection=yes;'', ''SET FMTONLY OFF exec ' + 
                               DB_NAME() + 
                              '.dbo.zzTempSP @A=1, @B=2'')'
EXEC(@sql)

SELECT *
FROM ##TempOutput

Great! However, if the SP was this instead:

CREATE PROCEDURE dbo.zzTempSP (@A INT, @B INT) AS CREATE TABLE dbo.#T (A INT, B INT)

INSERT INTO dbo.#T
SELECT   @A AS A, @B AS B

SELECT *
FROM dbo.#T

When I execute the same OPENROWSET code as before I receive the following error:

Cannot process the object “SET FMTONLY OFF exec DatabaseName.dbo.zzTempSP @A=1,@B=2”. The OLE DB provider “SQLNCLI10” for linked server “(null)” indicates that either the object has no columns or the current user does not have permissions on that object.

When I trim down the OPENROWSET code (by removing the dynamic stuff) to this:

SELECT   *
FROM OPENROWSET('SQLNCLI','Server=ServerName;Trusted_Connection=yes;',
                          'exec DatabaseName.dbo.zzTempSP @A=1,@B=2'
              )

I receive the following (much more useful) error:

Invalid object name ‘#T’.

Which is where I hit the wall. In my searching it seems that there is no solution, but I couldn’t bring myself to give up on it just yet.

And so I’m led to..

My question to you

Is anyone aware of any possible way to circumvent this error? Or is there possibly an alternative solution?

This process won’t be run frequently so I needn’t worry too much about the solution’s efficiency.

Any input would be greatly appreciated.

Thanks,
Zok

PS: Sorry about the formatting. I didn’t quite figure out the language tags.

  • 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-26T09:45:16+00:00Added an answer on May 26, 2026 at 9:45 am

    I had this question posted on SQL Server Central as well and some responses turned me back to looking for an answer within OPENROWSET (and finding it). One of the people turned me to this article‘s section on OPENQUERY. It states that in order to work around the issue with temp tables you simply add SET FMTONLY OFF to the execute line of your OPENQUERY/OPENROWSET statement like so:

    SELECT  *
    FROM    OPENROWSET( 'SQLNCLI',
                        'Server=SERVERNAME;Trusted_Connection=yes;',
                        'SET FMTONLY OFF; exec DatabaseName.dbo.zzTempSP @A=1,@B=2'
                      )
    

    However, if the procedure does not have SET NOCOUNT ON specified it still raises an error.
    I had a silly misunderstanding about SET NOCOUNT ON in the back of my head that stopped me from thinking, “Hey, can’t I just add SET NOCOUNT ON to the execute statement of OPENROWSET??” Once someone asked that question for me on the other thread it made all too much sense =) So, here is the solution I’ve been looking for all along:

    SELECT  *
    FROM    OPENROWSET( 'SQLNCLI',
                        'Server=SERVERNAME;Trusted_Connection=yes;',
                        'SET FMTONLY OFF; SET NOCOUNT ON; exec DatabaseName.dbo.zzTempSP @A=1,@B=2'
                      )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: I have a WPF desktop application which will be distributed on different machines
Scenario: A stored procedure receives from code a DateTime with, let's say DateTime.Now value,
Scenario: I have an application that pulls data from a SQL database as well
Scenario: I'm working on a solution that has many assemblies. The main assembly references
Scenario: I have imported the data from SQl Server to HDFS. The data stored
Scenario: I have a MySQL database of people and all their various features as
Scenario: Attempting to import many (>100), large(>1M recs) flat-files (csv). Problem: Many records are
Scenario: I have a Question which has 2 radio buttons & two subforms: subformA
Scenario Downloading an xlsx file to my local drive from a http location using
Scenario: Repository structure changed from /trunk/ to /projectName/trunk/ and the local copy is outdated

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.