In a new SSRS 2008 report, I am going to change the inline SQL to a stored procedure since that is a requirement for the project I am working on. The SQL works fine within the SSRS 2008 report, but has a problem in the stored procedure.
The error message that is displayed is the following:
Query execution failed for dataset Msg 8114, Level 16, State 1 Procedure spRec, line 0 Error converting data type varchar to int.
The stored procedure works if I select only 1 report. However if I select 2 or more reports that is when the above error occurs.
The SSRS 2008 report has 18 embedded tablixes within the main tablix. The embedded tablixes within the SSRS main tablix will display selected reports based upon a report parameter that a user. The embedded reports will be displayed based upon the report number. In addition, I only want the data for the selected reports to be returned from the SQL.
I want this to occur since the data from the runs will be more than is needed for each unique run. Note: The data returned will be all in the same format. There will be a column in each data row showing what report number the data should be selected for.
The report parameter is setup as allow multiple values and data type = text. The dataset to pass data to the report parameter looks like:
SELECT 'Locator' AS rptName, 1 AS rptValue
UNION
SELECT 'letter',2
UNION
SELECT 'Wallet ', 3
UNION
SELECT 'Cum Stu', 4
UNION
SELECT 'Attend', 5
UNION
SELECT 'Test',6
The SQL before each section looks like:
IF 1 in (@report)
IF 2 in (@report)
I have tried changing the properties of the report parameter to integer and the if statements listed above but it has not worked.
Thus can you tell me what I can do to solve my problem?
Sounds like you are passing in values from a dropdown that allows the end user to select more than one value. If this is the situation, then SSRS sends those values to the stored procedure in one long string. The more values that are checked in the dropdown, the longer the string. If the end user only checks one value, then everything will work in this situation (your IN clause can deal with just one value).
You have 2 options. Option 1. Make the SSRS dropdown a single value dropdown.
If that is not a viable option, then here is option 2:
You are going to have to make the data type for the @report parameter in the stored procedure something like an (n)varchar(1000); something long enough to handle a string with all possible values. Then you have to split the string into individual values so you can use them in the IN clause. Here is a split UDF I have used in the past.
Once you have that in place, you can change you code to look like this.
You may have to tweak this UDF to work with integers in your case, but the implicit conversion of data types may not be a problem. Or, change the data type in your SSRS dropdown to string.