SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SSRS 2008 will not return correct dataset from Stored Procedure


SSRS 2008 will not return correct dataset from Stored Procedure

Author
Message
samalex
samalex
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3557 Visits: 1101
Hi,

I have a stored procedure that generates different output datasets based on the parameter, but SSRS 2008 appears to be populating the column list from the first Select regardless of logic within the stored procedure and regardless of which parameter I feed it.

It needs to just execute the SP and run with what comes back, not evaluate the code behind the SP and try to guess what I want it to do, which it's doing incorrectly. I've tried setting-up the dataset using Text hard coding the parameter and also as Stored Procedure but same results either way. And I was able to verify SSRS is returning the first Select because i changed the order of the Selects and it changed my columns in the report.

Something else is if I open Query Designer it shows the correct dataset from the stored procedure, but clicking OK then Fresh Fields still shows the wrong dataset.

I'd really rather not split out the logic because it just doesn't make since to do so. I've done this before in other versions of SSRS, so does anyone know of a work around for this bug?

Thanks...

Sam Alex
samalex
samalex
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3557 Visits: 1101
Hi Everyone,

I found a 'solution' that works, but it's crummy I have to do this. I ended up bundling my SQL statements in to a variable and executing those variables at the end to make the report work. I guess if it doesn't find a valid Select it just executes it and runs with what comes back, which is what it should be doing from the start.

Still, any suggestions on how to avoid using Dynamic SQL to make this work? It's better then splitting the logic into multiple stored procedures, but still not what I hoped to do.

Thanks --

Sam Alex
Jack Corbett
  Jack Corbett
SSC Guru
SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)

Group: General Forum Members
Points: 124702 Visits: 15067
SSRS stores the names of the columns as part of the report definition (rdl file), that's the only way it can know what to display where in the report itself. So if you save the report with the columns FirstName, LastName, and BirthDate, those are the only columns the report itself knows about. SO if you change the parameter and the stored procedure now returns CompanyName, ContactName, PhoneNumber the report can't know about those columns because they are not stored in the report definition (rdl file). If I were doing this I would probably write the stored procedure so that it always returns ALL the columns. In my example I would always return FirstName, LastName, BirthDate, CompanyName, ContactName, PhoneNumber, but the unused columns would be NULL.



Jack Corbett
Consultant Straight Path Solutions
Dont let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a QuestionHow to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
samalex
samalex
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3557 Visits: 1101
Jack Corbett: SSRS stores the names of the columns as part of the report definition (rdl file), that's the only way it can know what to display where in the report itself. So if you save the report with the columns FirstName, LastName, and BirthDate, those are the only columns the report itself knows about. SO if you change the parameter and the stored procedure now returns CompanyName, ContactName, PhoneNumber the report can't know about those columns because they are not stored in the report definition (rdl file). If I were doing this I would probably write the stored procedure so that it always returns ALL the columns. In my example I would always return FirstName, LastName, BirthDate, CompanyName, ContactName, PhoneNumber, but the unused columns would be NULL.



Hi Jack,

Returning all rows is just as muddy as using dynamic SQL which is the best way I've found to make this work. This procedure will be used for processes outside of reporting, so I need the output to be clean.

My main gripe is that SSRS should see the output of the procedure, including parameters, and run with that instead of trying to get the column names from the procedure itself since the desired output wouldn't be known until it executes with parameters.

Thanks for the reply and take care --

Sam Alex
Jack Corbett
  Jack Corbett
SSC Guru
SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)SSC Guru (124K reputation)

Group: General Forum Members
Points: 124702 Visits: 15067
How would you suggest MS implement "dynamic" creation of columns within a dataset? At some point the engine has to know that FirstName goes in column1 if it is returned, but CompanyName goes in column1 if that is returned.



Jack Corbett
Consultant Straight Path Solutions
Dont let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a QuestionHow to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
thetodaisies
thetodaisies
Right there with Babe
Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)

Group: General Forum Members
Points: 793 Visits: 166
Please correct if i am wrong. both select statements returns same number of fields and the names of the fields are also the same but the no of records would be different from both selected statemets. if this is the case i really think it is some issue with the parameter value being checked. try returning the condition output from the SP. because SSRS doesnt do anything in SP execution logic.
satyajitrmohanty
satyajitrmohanty
SSC Journeyman
SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)

Group: General Forum Members
Points: 85 Visits: 204
Hi!!
hers the solution which seems to be working for me

Scenario- I had the stored procedure with IF ELSE in it which returned multiple result set depending on Input parameter.
i had returning four colunms for each result set for (daily,monthly,weekly,quaterly,yearly)

eg: DAILY....ACTIVE...CLOSED... SUSPENDED colunms for daily parameter grouped by daily

Problem-the dataset returnrd only for the first IF condition in SSRS designer eg-DAILY(excluded the the other but the results were showed along with BLANK values for 1 st colunm)

SOlution- create query in Desiner SSRS which returns table variable
the table variable will contain the results by excecuting main stored proc.
eg-
DECLARE @DATE TABLE (
PERIOD NVARCHAR(20),
ACTIVE int,
CLOSED int,
SUSPENDED int
)
if(@Frequency='DAILY')
begin
INSERT @DATE (PERIOD, ACTIVE, CLOSED,SUSPENDED)
exec sp_MAF_Report @Firstdate,@Lastdate,@Frequency
select PERIOD, ACTIVE, CLOSED,SUSPENDED from @DATE
end

else if(@Frequency='MONTHLY')
begin
INSERT @DATE (PERIOD, ACTIVE, CLOSED,SUSPENDED)
exec sp_MAF_Report @Firstdate,@Lastdate,@Frequency
select PERIOD, ACTIVE, CLOSED,SUSPENDED from @DATE
end

else if(@Frequency='WEEKLY')
begin
INSERT @DATE (PERIOD, ACTIVE, CLOSED,SUSPENDED)
exec sp_MAF_Report @Firstdate,@Lastdate,@Frequency
select PERIOD, ACTIVE, CLOSED,SUSPENDED from @DATE
end

this one works for me perfectly fine
Thanks & regards
Satyajit
samuel.bayeta
samuel.bayeta
Valued Member
Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)

Group: General Forum Members
Points: 71 Visits: 7
Hi Every one, Though this sounds a late response to a 6 years old question, I happen to feel it is beneficial to respond a best answer as others might have referred this website for their day to day need. in short the answer to this is fake SSRS by creating your stored procedure with a hint SET FMTONLY OFF. This is a dramatic trick.
DB4food
DB4food
Valued Member
Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)

Group: General Forum Members
Points: 73 Visits: 18
Using SET FMTONLY OFF does not work.

Some suggest using Exec under text in the dataset properties.

But doing this way won't allow me to pass parameters.

So if anyone has a solution for either of this, I would be really appreciated:

1) Have the stored procedure return the fields

2) Using the workaround of Exec, how do I pass parameter?

I have google everywhere.

This suggestion below does not work:

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/d8c68166-fca2-4da4-8af9-107363d96c57/ssrs-not-passing-fieldsparameters-to-report-when-stored-procedure-keeps-parameters-inside-if?forum=sqlreportingservices




samuel.bayeta (4/25/2016)
Hi Every one, Though this sounds a late response to a 6 years old question, I happen to feel it is beneficial to respond a best answer as others might have referred this website for their day to day need. in short the answer to this is fake SSRS by creating your stored procedure with a hint SET FMTONLY OFF. This is a dramatic trick.

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search