Try the following:
SELECT * FROM OPENQUERY("FOO\SQL2012", 'SET FMTONLY OFF; EXEC mySchema.myStoredProc;') X;
The reason for this is that when the stored procedure is executed on the linked server, the provider first tries to determine the shape of the resulting rowset. He does this by writing SET FMTONLY ON; , and then launches your statement. In a stored procedure that does not use temporary tables, this works great. The query parser basically performs a dry run, without actually receiving all the data, but only metadata (it seems to show an approximate execution plan).
The problem is that when a stored procedure uses temporary tables, it fails because the metadata of the temporary table does not exist: it cannot be collected using a meta-analysis that works for stored procedures that do not use temporary tables. Thus, because of this, it will be manually SET FMTONLY OFF; in a package that executes a stored procedure.
Remember that with this method, the stored procedure is executed twice . The first time to collect metadata (data is discarded), and the second time to actually return the data. If the called stored procedure is particularly expensive or has side effects, you may have to make a discount.
Finally, note that this trick does not work for every stored procedure. There are things stored procedures can do this, just throw a wrench in the works. I do not know all the possibilities, but one of them returns several sets of records.
In response to your update, that SET FMTONLY OFF does not work: can you change the structure of your SP to not use a temporary table, or use a permanent table with a session? Any of these options could do the job. In SQL Server 2012, you can also transfer data with table parameters .
You might like to read Erland Sommarskog How to Share Data Between Stored Procedures , as it can serve as a source of inspiration for your goal.
ErikE
source share