March 7, 2008 at 9:19 am
I've been looking on the internet for this, but i don't if its not posible or i'm not making a good search, if anyone knows, thnks
March 7, 2008 at 9:46 am
You can only select the results of a stored procedure by dumping the results into a table. You have to make sure that your table has the same number of returned columns as the stored procedure. In addition to a table, you can store the results into a table variable, and temp table.
e.g.
create table mytable(
col1 int,
...
)
insert into mytable
exec mystoredprocedure
select *
from mytable
March 7, 2008 at 10:52 am
I'm not so sure that's true, Adam. I believe you can use OPENQUERY for this.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 7, 2008 at 11:05 am
I'm not so sure that's true, Adam. I believe you can use OPENQUERY for this.
This is what I get for speaking in absolute :hehe:. Well on a positive note I learned something new. I have never used this function before, but will research it to find out more.
Edit: Remove only
You can select the results of a stored procedure by dumping the results into a table. You have to make sure that your table has the same number of returned columns as the stored procedure. In addition to a table, you can store the results into a table variable, and temp table.
March 7, 2008 at 11:11 am
After briefly looking at the function. I would still use the proposed solution for performance benifts, but will acknowledge that openquery can accomplish the task.
March 7, 2008 at 11:25 am
Ok, with openquery i found two problems, according to the msdn Library, open query only returns the first row of the query and it doesn't work for stored procedures with parameters... so, i can't use openquery. I'm already using temp tables, but i'm triying to avoid them because i think that its not good for performance and sometimes i have to create temp tables with 100 columns, and in the end i only use five, so i think is a waste. Thanks, see you on the road
March 7, 2008 at 11:32 am
What? One row? You'll need to show me that URL... take a look at Books Online, instead... example they give uses SELECT TOP 1000 *...
--Jeff Moden
Change is inevitable... Change for the better is not.
March 7, 2008 at 12:43 pm
Alright here is, http://technet.microsoft.com/es-es/library/ms188427.aspx, its in spanish. i hope you can understand... so my stored procedure has parameters, OPENQUERY can still work for me?
March 7, 2008 at 1:13 pm
Sorry... I can't read Spanish...
--Jeff Moden
Change is inevitable... Change for the better is not.
March 7, 2008 at 1:30 pm
The link he posted is the same as BOL. This is the remark he is concerned with
OPENQUERY does not accept variables for its arguments.
In SQL Server 2000 and later versions, OPENQUERY cannot be used to execute extended stored procedures on a linked server. However, an extended stored procedure can be executed on a linked server by using a four-part name. For example:
March 7, 2008 at 1:39 pm
Jeff Moden (3/7/2008)
Sorry... I can't read Spanish...
All right smarty....He's pointing at the BOL entry for OPENQUERY...
http://technet.microsoft.com/en-us/library/ms188427.aspx
Both OpenQuery and OpenRowset need "static" SQL to run. you can't pass a variable with SQL into it.
MrBungle - you COULD wrap the entire OPENQUERY/OPENROWSET in dynamic SQL in order to do this, and then use sp_ExecuteSQL to fire it. Or - you create the linked server, create a temp table with the right columns, and run something like
Insert #MyTempTable
Exec MyLinkedServer.MyDB.MyUser.MyStoredProc @var='123'
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
March 7, 2008 at 4:02 pm
All right smarty....He's pointing at the BOL entry for OPENQUERY...
Heh... truth be told, I didn't even look once he said it was in Spanish.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 12 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply