Urgent! How to use exec result as part of select statement?

  • Hi all,

    Assume there is a system stored procedure: spSystemSP, will return some result,  how can I write a statement like:

    select myobject, exec spSystemSP as xxx, from mytable

    Thanks.

  • You could declare a variable of whatever datatype spSystemSP would return, then assign that variable to the results of spSystemSP and include that variable in your select. 

    Example:

    declare @spResults int

    set @spResults = 0

    exec @spResults = spSystemSP

    select myobject, @spResults as XXX, from mytable

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • If you are using MS SQL Server 2000 you can use user defined functions on a row by row basis. What are you trying to do?

  • With regards to your SP, are you after

    a) The resultset the SP returns

    b) The value of an output param

    c) The return value of the SP

    ?

  • I am using system sp to get sort of recordset, and then I need to combine this recordset within other select statement. I doubt if I can do this using single select statement, which is required in my coding. So, I decided to analysis the returned recordset outside SQL.

    Thanks for all response.

Viewing 5 posts - 1 through 4 (of 4 total)

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