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.

 All Forums
 SQL Server 2008 Forums
 Analysis Server and Reporting Services (2008)
 SSRS 2008 Doesn't like SPs with temp tables

Author  Topic 

theboyholty
Posting Yak Master

226 Posts

Posted - 2011-03-03 : 05:55:40
I've been using SSRS 2005 for years but now am in a new job where they are using Sql Server 2008 R2 and therefore SSRS 2008.

I'm working on my first report (chosen becuase of my experience of SSRS 2005) and i've an SP that contains temp tables. When I try to include it in my report though, I get an error message.

Just to make sure I'm not being really daft (because 2008 looks very different from 2005), I've created a new report and a data source. Then i've created a new dataset and for my data source i've selected the one i'd just created. From the Query type drop down list i've selected Stored Procedure and then the list has been populated with all the SPs from that database. I've selected the correct SP and when I click OK, I get the following message:

Could not create a list of fields for the query. Verify that you can connect to the data source and that your query syntax is correct. An item with the same key has already been added"

Any ideas on what I can do to get this working would be much appreciated.


---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk The official unofficial website of Bury Football Club

yadhu_cse
Constraint Violating Yak Guru

252 Posts

Posted - 2011-03-03 : 06:20:14
there is an error in ur sp. if send sp i can tel u. better use cte insted of temp table
Go to Top of Page

theboyholty
Posting Yak Master

226 Posts

Posted - 2011-03-03 : 06:30:31
My SP runs fine both as a standalone query and as an SP. The code, however is below:

ALTER PROCEDURE [dbo].[SP_RPT_PMOutstandingTasks]

AS

SELECT
[user_id]
,user_username as Username
,contact_first_name + ' ' + contact_last_name as FullName
INTO #Users
FROM OPENQUERY(Project,'SELECT u.user_id,u.user_contact,u.user_username,c.contact_id,c.contact_first_name,c.contact_last_name
FROM Users u
INNER JOIN contacts c ON c.contact_id=u.user_contact')

CREATE UNIQUE INDEX IX_Users_UserID ON #Users([User_ID])

---------------------------------------------------------------------
SELECT *
INTO #Tasks
FROM OPENQUERY(Project,'SELECT task_id,task_name,task_start_date,task_end_date,task_description,task_creator,task_owner,task_contacts,Task_Percent_Complete FROM tasks WHERE Task_Percent_Complete < 100')

CREATE UNIQUE INDEX IX_Tasks_Task_ID ON #Tasks(Task_ID)
CREATE INDEX IX_Tasks_Task_End_Date ON #Tasks(task_end_date)

---------------------------------------------------------------------
SELECT *
INTO #UserTasks
FROM OPENQUERY(Project,'SELECT User_ID,Task_ID FROM User_Tasks')

CREATE INDEX IX_UserTasks_User_ID ON #UserTasks([User_ID])
CREATE INDEX IX_UserTasks_Task_ID ON #UserTasks(Task_ID)

---------------------------------------------------------------------
DECLARE @dteToday DATETIME
SET @dteToday = DATEADD(DAY,0,DATEDIFF(DAY,0,GETDATE()))
---------------------------------------------------------------------


SELECT DISTINCT
t.task_id
,t.Task_Name
,t.Task_Description
,t.Task_Start_Date
,t.Task_End_Date
,t.Task_Percent_Complete
,ut.task_id
,u3.FullName as AssignedTo

FROM #Tasks t
LEFT JOIN #UserTasks ut ON ut.task_id=t.task_id
LEFT JOIN #Users u3 ON u3.[user_id]=ut.[User_ID]

WHERE
t.Task_Percent_Complete < 100

AND ut.[User_ID] IS NOT NULL
AND ut.task_id NOT IN (1,5,14,24,30,33,37)

ORDER BY u3.FullName,t.Task_End_Date

DROP TABLE #Users
DROP TABLE #Tasks
DROP TABLE #UserTasks


The reason I've gone with the temp tables rather than CTEs is because I'm using OPENQUERY to access a MySQL database and I need to add indexes to the temp tables.

---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk The official unofficial website of Bury Football Club
Go to Top of Page
   

- Advertisement -