I have SQL Server 2012 full version installed on my development PC.
I am trying to follow the examples here, which show how to create a new temporary table using a stored procedure as the source of the data. I am trying to combine the results of several stored procedures into a single temporary table (the column-structure/definition of the various resultsets is identical).
To test if the plumbing is working, I issue this query:
SELECT * FROM OPENQUERY("FOOSQL2012", 'exec mySchema.myStoredProc')
But I'm getting this error from that simple test-the-plumbing select query:
Msg 11526, Level 16, State 1, Procedure sp_describe_first_result_set, Line 1
The metadata could not be determined because statement 'insert #tmp(foo1, foo2, foo3)
select 'O' as foo1, foo2, foo3' in procedure 'myStoredProc' uses a temp table.
If I understand the error correctly, OPENQUERY depends upon the server being able to extract the column datatypes from the persistent definition in the database, and the temporary table instantiated in my stored proc, being ephemeral, lacks a persistent definition. If that is the case, is there any setting that tells OPENQUERY to do the best it can and try to make an intelligent guess at the column datatypes?
Here's the dummy SP I'm testing with:
create proc testproc
as
begin
create table #test
(id int, name varchar(5) );
insert into #test(id,name)values(1,'xxx');
select * from #test;
--drop table #test; -- tried dropping and not dropping, same error either way
end
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…