Here is a simple example of a routine to capture the results of an executed stored procedure so they can be acted upon.  To be honest, I am posting this completely for selfish reasons as I tend to forget this syntax more often than I wish to admit.

CREATE TABLE #Results
(
    Column1 varchar(64),
    Column2 varchar(64),
)

INSERT INTO #Results
EXEC SampleStoredProcedure @param1, @param2, @param3

SELECT Column1, Column2
FROM #Results

If, per chance, there is a way to include stored procedure EXEC as a derived table within a sql select statement, I would love to hear about it.  Conceptually, I am thinking something like the following:

SELECT * FROM (EXEC SampleStoredProcedure @param1, @param2, @param3) A

5 Comments to “Capture Results of EXEC SP”

  1. Chris says:

    Yes, i want that syntax to work.. so simple.. sprocs are pre-compiled so you should not have to create a temp table and define it’s schema.. i want SELECT * FROM (EXEC SampleStoredProcedure @param1, @param2, @param3) A !!!

  2. You can do something like.

    DECLARE @RetVal VARCHAR
    EXEC @RetVal = spGetString @param1, @param2

  3. Hey there! I’ve been reading your website for a while now and finally got the bravery to go ahead and give you a shout out from Kingwood Tx! Just wanted to tell you keep up the excellent work!

  4. Howdy would you mind stating which blog platform you’re working with? I’m looking to start my own blog soon but I’m having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I’m looking for something completely unique. P.S Sorry for getting off-topic but I had to ask!

  5. This very blog is really educating and informative. I have chosen helluva interesting tips out of it. I’d love to return again soon. Thanks a bunch!

Leave a Reply

You can wrap your code with [ruby][/ruby] or [python][/python] blocks for syntax highlighting and you can use these traditional tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>