Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ddz
Starting Member
4 Posts |
Posted - 2004-11-02 : 16:24:54
|
| I am trying to take the results of a stored procedure and place those results in a new table. But the stored procedure that I created to do this seems to only run the query, but not create the table. (I don't get any error messages when testing it with SQL Query Analyzer.) What am I doing wrong?Here's the code that is suppose to create a new table: CREATE PROCEDURE [dbo].[CountHelpDeskResponsesTable] ASCREATE TABLE #SumHelpDeskResponses( ContactID int, Email varchar(50), Form varchar(50), Phone varchar(50), Walk varchar(50))INSERT INTO #SumHelpDeskResponses EXECUTE CountHelpDeskResponsesSELECT * FROM #SumHelpDeskResponsesDROP TABLE #SumHelpDeskResponsesGOHere's the code from the stored procedure (that is generating a crosstab query):CREATE PROCEDURE [dbo].[CountHelpDeskResponses] ASSELECT ContactMethods.ContactID,SUM(CASE ContactHelpDesk WHEN 'email' THEN 1 ELSE 0 END) AS Email,SUM(CASE ContactHelpDesk WHEN 'form' THEN 1 ELSE 0 END) AS Form,SUM(CASE ContactHelpDesk WHEN 'phone' THEN 1 ELSE 0 END) AS Phone,SUM(CASE ContactHelpDesk WHEN 'walk' THEN 1 ELSE 0 END) AS WalkFROM ContactMethodsGROUP BY ContactMethods.ContactIDGOHere's what my table, ContactMethods, looks like:(Dashes are used to preserve the spacing in this posting.)ContactID- ContactHelpDesk1 -------- email2 -------- walk3 -------- form4 -------- phone5 -------- email6 -------- walk7 -------- formHere's what the results look like from the CountHelpDeskResponses stored procedure:ContactID- Total of ContactStudent- email- form- phone- walk1 -------- 1 ---------------------- 12 -------- 1 ------------------------------------------ 13 -------- 1 ----------------------------- 14 -------- 1 ----------------------------------- 15 -------- 1 ---------------------- 16 -------- 1 ------------------------------------------ 17 -------- 1 ----------------------------- 1 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-11-02 : 16:33:51
|
| A temp table is dropped when the SP that created it ends. Cretae the temp table then call the sp to populate it.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-11-02 : 16:37:34
|
| Why are you doing this?What do you mean seems only to run a query?Brett8-) |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2004-11-02 : 16:39:25
|
I don't see the point in using a proc that creates a temporary table, which only lives while the proc runs.Just do your code:CREATE TABLE #SumHelpDeskResponses(ContactID int,Email varchar(50),Form varchar(50),Phone varchar(50),Walk varchar(50))INSERT INTO #SumHelpDeskResponses EXECUTE CountHelpDeskResponsesSELECT * FROM #SumHelpDeskResponsesDROP TABLE #SumHelpDeskResponses But not within a sp. while pouring coffee...rockmoose |
 |
|
|
|
|
|
|
|