Friday, March 30, 2012

Reporting Services Stored Procedure Dataset

I have a big SQL Stored Procedure which works with a cursor inside of it. During the procedure the data is inserted into a table and at the end is a SELECT statement from that table. The problem is that when i create a dataset with that stored procedure and i run it in the Data tab i get the correct select, but in the Fields section of the Report I don't get the fields from the last SELECT, but the fields from the cursor. Am I doing something wrong or is this a bug and how can i fix it.
Thanks!does it return the correct result set when you run it from QA ?|||Yes, it does return the correct dataset. I am using sql 2005 and if I have the procedure like his:

DECLARE Mycusor CURSOR FOR SELECT Field1, Field2, ...
OPEN CURSOR ...
FETCH NEXT ...
WHILE @.@.FETCH_STATUS > 0 ...
INSERT INTO tmp ...

SELECT * FROM tmp

If the procedure is like this then in Sql 2005 when i run it i get the data from tmp and in Reporting Services i get a dataset containg Field1, Field2 with no rows in it.
Do you have any idea?|||dont you have a close/deallocate cursor ? heres a template for a cursor.


DECLARE rs CURSOR
LOCAL
FORWARD_ONLY
OPTIMISTIC
TYPE_WARNING
FOR SELECT
OPEN rs
fetch next from rs into
WHILE ( @.@.FETCH_STATUS = 0 )
begin
-- your DML stmts.

FETCH NEXT FROM rs INTO
END

close rs
deallocate rs

and you would need to do a select after deallocating the cursor.

hth

No comments:

Post a Comment