SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to save sp exec result into a temp table


How to save sp exec result into a temp table

Author
Message
halifaxdal
halifaxdal
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1979 Visits: 1744
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.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87240 Visits: 41113
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
MyDoggieJessie
MyDoggieJessie
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6704 Visits: 7394
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" ;-)
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87240 Visits: 41113
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Jared Karney
Jared Karney
SSCertifiable
SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)

Group: General Forum Members
Points: 5000 Visits: 3694
Jeff Moden (1/18/2013)
INSERT INTO #BreakDownByCategories
EXEC dbo.spGetCategoriesByDocIDAsTable @DocID


Thanks,
Jared
PFE - Microsoft
SQL Know-It-All
How to post data/code on a forum to get the best help - Jeff Moden
halifaxdal
halifaxdal
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1979 Visits: 1744
Thank you all for the replies
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search