So below is an example of my issue without any data in. I'm having an issue where by I've created a stored proc with an IF in so that a parameter dictates which data set I create in SSRS, however when I pass the parameter in SSRS I don't get the dataset I request. My example script is as follows:
USE [InfoPortal]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_Report_SSRSTest]
(
@ReportType VARCHAR(255) = NULL
, @Debug VARCHAR(1) = NULL
)
AS
BEGIN
SET NOCOUNT ON
SET FMTONLY OFF
CREATE TABLE #data1
(
number INT
,text1 VARCHAR(100)
,text2 VARCHAR(300)
)
CREATE TABLE #data2
(
number INT
,text3 VARCHAR(100)
,text4 VARCHAR(300)
)
IF @ReportType = 'Y'
BEGIN
SELECT
number
, text1
, text2
FROM #data1
END
ELSE
BEGIN
SELECT
number
, text3
, text4
FROM #data2
END
END
So when I go into Datasets > Add Dataset, I select a "Query type" of "Stored Procedure" and select the stored proc above. I then go to parameters and in @ReportType I enter "Y" and @Debug I enter "N". I click refresh fields and then ok. But rather than passing "Y" into the stored proc it seems to be passing nothing because I get the ELSE part of the stored proc returned as available fields in my dataset. When I try with @ReportType "N" and @Debug "N" I get the available fields I require but Im assuming that this is because its passing a NULL into @ReportType.
Is there something I am missing?
When I run the proc SSMS with the same parameters as above I get the datasets I require. When I run the stored proc in Query Designer within SSRS it is also fine.
So why would my report be passing a NULL as a parameter to the stored proc even though i'm setting the parameter to a value in Dataset properties?
it seems to be passing nothing, have you confirmed? UseSQL Server Profilerdetermine that this is correct. - Tak