dbTalk Databases Forums  

Populate Temp Table from SP?

microsoft.public.sqlserver.mseq microsoft.public.sqlserver.mseq


Discuss Populate Temp Table from SP? in the microsoft.public.sqlserver.mseq forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stingray
 
Posts: n/a

Default Populate Temp Table from SP? - 03-15-2005 , 05:21 PM






I have a question that I haven't been able to find an answer to in either the
help files or Technet/MSDN searches. First a little background. I have a
number of SPs that pull the same basic data but manipulate it in different
ways (e.g. some add address information for targeted mailing lists, others
summarize the data for executive reports, etc.)

What I would like to do is create a single SP to pull the raw data and then
pull the results of that SP into a temp table within another SP to then
further refine for the different reports.

For Example:

I have a stored procedure SP_Dues_Data that gives me my dues paid for the
year in some form like:

custid, invoicedate, prodname, amount,...

and I want to have another SP such that:

Create procedure SP_Dues_Report
@param1,
@param2
AS

Create Table #TempDuesData
(custid, invoicedate, prodname, amount,...)

insert into #TempDuesData
select [results of 'exec SP_Dues_Data @param1, @param2]

do stuff
..
..
..

select * from #tempDuesData t
join CustData c
on c.custid = t.custid
..
..
..

Hopefully this gives you a picture. My reasoning is, if I need to make any
changes to the SP for the underlying data, I just need to change the one SP.
As it is now, I'm copying the updated core statements to select the data and
pasting it into multiple report SPs to get them all reporting the same data.
Is this possible? Does it even make sense to try? Am I just taking the wrong
path? I appreciate any insight.



Reply With Quote
  #2  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Populate Temp Table from SP? - 03-16-2005 , 03:56 PM






On Tue, 15 Mar 2005 15:21:01 -0800, Stingray wrote:

(snip)
Quote:
Create Table #TempDuesData
(custid, invoicedate, prodname, amount,...)

insert into #TempDuesData
select [results of 'exec SP_Dues_Data @param1, @param2]
(snip)
Is this possible? Does it even make sense to try? Am I just taking the wrong
path? I appreciate any insight.
Hi Stingray,

I believe this is the syntax you're after:

CREATE TABLE #TempDuesData
(custid int NOT NULL, -- Just guesses!!
invoicedata datetime NOT NULL, -- Just guesses!!
....,
PRIMARY KEY (....)
)

INSERT INTO #TempDuesData (custid, invoicedata, ...)
EXEC SP_Dues_Data @param1, @param2

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


Reply With Quote
  #3  
Old   
Stingray
 
Posts: n/a

Default Re: Populate Temp Table from SP? - 03-16-2005 , 04:29 PM



Now if you could tell me why I have never been able to get it to work before,
I'll be set. . Thanks again for your insight. This will save me much time
and effort down the road.

"Hugo Kornelis" wrote:

Quote:
On Tue, 15 Mar 2005 15:21:01 -0800, Stingray wrote:

(snip)
Create Table #TempDuesData
(custid, invoicedate, prodname, amount,...)

insert into #TempDuesData
select [results of 'exec SP_Dues_Data @param1, @param2]
(snip)
Is this possible? Does it even make sense to try? Am I just taking the wrong
path? I appreciate any insight.

Hi Stingray,

I believe this is the syntax you're after:

CREATE TABLE #TempDuesData
(custid int NOT NULL, -- Just guesses!!
invoicedata datetime NOT NULL, -- Just guesses!!
....,
PRIMARY KEY (....)
)

INSERT INTO #TempDuesData (custid, invoicedata, ...)
EXEC SP_Dues_Data @param1, @param2

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


Reply With Quote
  #4  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Populate Temp Table from SP? - 03-16-2005 , 04:58 PM



On Wed, 16 Mar 2005 14:29:24 -0800, Stingray wrote:

Quote:
Now if you could tell me why I have never been able to get it to work before,
Sorry - wrong group! Try alt.psychology.blindspot :-P

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.