Can I Do a Select *FROM StoredProcedure ??

  • 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

  • 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

  • I'm not so sure that's true, Adam. I believe you can use OPENQUERY for this.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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.

  • 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.

  • 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

  • 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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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?

  • Sorry... I can't read Spanish...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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:

    link http://msdn2.microsoft.com/en-us/library/ms188427.aspx

  • 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?

  • 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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply