Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Services / Reporting Services / July 2008

Tip: Looking for answers? Try searching our database.

return results from stored procedure

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan - 17 Jul 2008 10:24 GMT
Hi All,

I have managed to get my Reporting Services 2005 up and running.
I have a question though: Instead of defining my dataset as a text query
(such as select * from table..) I would like to define it as executing a
stored procedure. This stored procedure will be a little bit more complex
than just a simple (select * from..)

In other words, it will look into some tables and then iterate through some
values...

WHILE
BEGIN
-- get my values here
-- Here i Used to build a string with the data needed and just print it
(e.g., SET @PrintString = @Value + N' ' + @Value2... )
-- PRINT @SPrintString
FETCH NEXT..@Value, @Value2..
 ...
END

I used to create a string and print that, but now I would like the results
in a table form so that Reporting Services renders them correctly as a
report. Should I somehow create a temporary table and insert the values in
it and then have my query something of the form (INSERT INTO TempTable exec
sp_StoredProcedure) ? Is this the correct way of doing it or should I go
about it a different way ? And if this is the solution, how would I create
this table and how would I actually return it ? Would I just create it
before calling the stored procedure and drop it after that?

Thanks.
Bruce L-C  [MVP] - 17 Jul 2008 14:45 GMT
In your stored procedure do the following:
create table #Result (valuestring as varchar(512))

then instead of your print statement do this
insert #Result select @SPrintString

Your last statement in the SP should be
select * from #Result

In RS select the type as stored procedure.

Note, do not explicitly drop the table. The temp table will automatically go
away once RS is done with it.

Signature

Bruce Loehle-Conger
MVP SQL Server Reporting Services

> Hi All,
>
[quoted text clipped - 27 lines]
>
> Thanks.
Dan - 17 Jul 2008 16:01 GMT
Hi,

> In your stored procedure do the following:
> create table #Result (valuestring as varchar(512))
[quoted text clipped - 9 lines]
> Note, do not explicitly drop the table. The temp table will automatically
> go away once RS is done with it.

Thank you a lot for your help. Your answer clearly explains a very good
solution. I have a follow-up question if I may... Will this by any chance
create problems when multiple users would access the report ? In other
words, if user 1 runs the report and the table #result si created and then
something is inserted, and before it is dropped user 2 runs the same
procedure... would that cause the #result table to be populated incorrectly
(2 inserts instead of one / user) or is the table somehow part of a
"Session" and thus separate for each client ?

Dan
Bruce L-C  [MVP] - 17 Jul 2008 16:12 GMT
Correct, it is part of the session. If you used a global temporary table ##
instead of # then you would have a problem. Also, it is possible to put
T-SQL in the dataset tab itself and theoretically you can put a temp table
there. But then you get exactly the problem you mention below. You could
actually take your code from your stored procedure and past it into the
generic query designer (two panes, you switch with one of the buttons to the
right of the ...). However, in most cases this is a bad idea due to how RS
processes reports. Put the logic in the stored procedure and everything will
work correctly and you will have no problems whatsoever.

If my comments about putting T-SQL in the dataset pane of RS is confusing
just ignore it. The important point is that yes the temp table in a stored
procedure is 100% multi-user safe.

Signature

Bruce Loehle-Conger
MVP SQL Server Reporting Services

> Hi,
>
[quoted text clipped - 22 lines]
>
> Dan
Dan - 17 Jul 2008 16:59 GMT
> Correct, it is part of the session.

Thanks for clarifying this for me. I feel much better now knowing this.

> If my comments about putting T-SQL in the dataset pane of RS is confusing
> just ignore it. The important point is that yes the temp table in a stored
> procedure is 100% multi-user safe.

Thanks for all the details. I understand perfectly everything you said.

Thanks again for all your help and time,
Dan
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.