Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to save sp exec result into a temp table Expand / Collapse
Author
Message
Posted Friday, January 18, 2013 1:34 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, April 14, 2014 8:22 AM
Points: 759, Visits: 1,353
Hello,

I have a sp where I created a temp table, I need then insert the result of another sp into that table.

I end up write code like this:

		set @sql = '
Insert into #BreakDownByCategories
Select * FROM OPENROWSET( ' + '''' + 'SQLNCLI' + '''' + ',' + '''' +
'Server=(local);Trusted_Connection=yes;' + '''' + ',' + '''' +
'SET FMTONLY OFF; SET NOCOUNT ON; exec spGetCategoriesByDocIDAsTable ' + Convert(varchar, @DocID) + '''' + ')'
exec (@sql )

I wonder if there is a better way to do this since OPENROWSET is usually disabled.

Thank you.
Post #1409083
Posted Friday, January 18, 2013 2:40 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:27 AM
Points: 35,980, Visits: 30,272
INSERT INTO #BreakDownByCategories
EXEC dbo.spGetCategoriesByDocIDAsTable @DocID


--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." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1409111
Posted Friday, January 18, 2013 2:45 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 8:26 AM
Points: 3,734, Visits: 7,075
Jeff Moden (1/18/2013)
INSERT INTO #BreakDownByCategories
EXEC dbo.exec spGetCategoriesByDocIDAsTable @DocID

I believe an accidental typo?
INSERT INTO #BreakDownByCategories
EXEC dbo.spGetCategoriesByDocIDAsTable @DocID


______________________________________________________________________________
"Never argue with an idiot; They'll drag you down to their level and beat you with experience"
Post #1409113
Posted Friday, January 18, 2013 2:53 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:27 AM
Points: 35,980, Visits: 30,272
MyDoggieJessie (1/18/2013)
Jeff Moden (1/18/2013)
INSERT INTO #BreakDownByCategories
EXEC dbo.exec spGetCategoriesByDocIDAsTable @DocID

I believe an accidental typo?
INSERT INTO #BreakDownByCategories
EXEC dbo.spGetCategoriesByDocIDAsTable @DocID


Thanks for the catch. You are correct.... the second "exec" should not have been there. Was a Copy/Paste error on my part.

Repaired my post.


--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." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1409116
Posted Friday, January 18, 2013 3:00 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, April 11, 2014 7:37 AM
Points: 2,673, Visits: 3,325
Jeff Moden (1/18/2013)
INSERT INTO #BreakDownByCategories
EXEC dbo.spGetCategoriesByDocIDAsTable @DocID


Thanks,

Jared
SQL Know-It-All

How to post data/code on a forum to get the best help - Jeff Moden
Post #1409117
Posted Monday, January 21, 2013 8:34 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, April 14, 2014 8:22 AM
Points: 759, Visits: 1,353
Thank you all for the replies
Post #1409582
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse