SSRS report - query parameter - reporting-services

I am using SQL server as my data source. The dataset query is like this simplified for this question:
select * from customers where custid = #ReportParam
The wizard creates a report parameter ReportParam and also maps dataset varuable #ReportParam to report parameter ReportParam.
Works fine in Report Builder, but when I run it from my app I get:
System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable
"#ReportParam"
Not sure why it is happening. Any idea?
Thanks

Related

In SSRS, a Date Time parameter on Preview is not matching the deployed report

In SSRS, a Date Time parameter on Preview is not matching the deployed report. Is this something someone else has encountered? The RDL code is identical. Is it the fact that, sometimes, a local preview is just a simulation of functionality? Is it because the display in preview sometimes uses cached data?
I have a SSRS report that, when I preview it in Visual Studio locally, the date shows as 2/10/2019 but when the RDL code is deployed on the server, the date shows as 2/7/2019.
The date time variable is based on a parameter on the report, called rundate, and it has a Default Value of 2/10/2019.
So I think the same thing should happen on the Report Server that happens locally in preview mode.
The report has four datasets and, as a test, I have set each four to have the SQL line that sets the rundate value like so:
SET #rundate = '2019-02-10'
but on the report server, when I load the report, it throws this error:
Must declare the scalar variable "#rundate". Must declare the scalar variable "#rundate".
It is in a cascading tabbed error message that looks like this:
An error occurred during client rendering.
An error has occurred during report processing.
Query execution failed for dataset 'ThirdDataset.
Must declare the scalar variable "#rundate". Must declare the scalar variable "#rundate".
So, why does it run locally and not on the server? The "ThirdDataset" is a false name I have given here. The actual name is redacted. But, I have noticed that this would be the first dataset run if they are run alphabetically. So this leads me to the question: why doesn't the report recognize this as a parameter and why does it complain that it is not declared?
============
UPDATE:
I have set the rundate to be part of a data-driven subscription in a report like so:
SELECT convert (date, DATEADD (DAY, -2 , SYSDATETIME())) as rundate
Which is two days ago. Since it is 2/11/2019 today, the rundate parameter passed to the SSRS report on the server should be 2/9/2019.
For fun, to test this out, I set the Default Value rundate parameter to be 8/8/2018 in hopes that the data-driven report would set it properly.
In preview mode locally on Visual Studio, a textbox that set to show the [#rundate] Expression shows 8/8/2018 which is what I would expect, but the Datasets are designed to run off this parameter. Since there is nothing that the sql should retrieve from the database that is that old, the graphs and charts in preview mode should turn up completely empty. Why do they show data?!
Next, let's see what the emailed subscription alert says. It had the date of 2/11/2019 12:00:00 AM. If the data-driven subscription ran like it shouold ahve run, it should of had the date of 2/9/2019 from
SELECT convert (date, DATEADD (DAY, -2 , SYSDATETIME())) as rundate
Why did this not work?
On the SSRS server, the RDL file has a parameter default value of 2/11/2019 12:00:00 AM but why did the report get THIS default value? What am I doing wrong and how can I fix this?
As a test, I set this default date/time parameter to 12:12:34 for its time to see what would happen. It reveiled that, yes, this is the date time stamp that is being sent to the report. So I unchecked the "Has Default" box
Then, I noticed in the Step 5 of the data-driven subscription I could not advance to Next > without making a small change:
So, what should happen? Will it show the wacky 8/8/2018 value? Will it show the date from two days ago?
Default values for report parameters are deployed only once to the report server, and then they keep their default value after subsequent deployments. This is so that default parameter values used in development don't overwrite the desired parameter defaults on the production server.
So it looks like when the report was first deployed, #rundate had the default value 2/7/2019 but has since been changed on the local report to 2/10/2019. Go into your report server, find the report and go into the Report Parameters section to edit the parameters and change the default value to what you want it to be (deleting the report from the report server and re-deploying it with the updated parameter will have the same effect, but note that the parameter will maintain that default value going forwards). Alternatively, set the report parameter using an expression so that it is continually up to date.
Regarding updating your parameter value in the Sql statement using the SET statement, you can't actually do it that way - you need to set it in the report's parameter list so that SSRS can set the parameter value. Consequently, your databse server is complaining that you are trying to set the value of a local variable that hasn't been defined in your Sql statement, and thus throws an error message.
So you need to set up the Report Parameters in the report parameters section in the report designer. Your Sql can then reference your parameters like so:
SELECT * FROM MyTable WHERE SomeDate >= #rundate
The parameters normally get mapped into your dataset automatically but you might want to check this by going into the Parameters settings on your dataset to make sure. If the parameter doesn't exist there, set it up.
After lengthy trial and error, I found that the answer was to NOT have the parameter set to have a default value on the SSRS Report Server.

SSRS 2012: Cannot add multi value parameter '?' for dataset XYZ because it is not supported by the data extension

Scenario: I am working with a Firebird database (somewhat similar to MySQL) connected to Microsoft SSRS 2012 via ODBC connection manager.
I have a huge stored procedure (which I am not supposed to modify at all) given by our client. The stored procedure has a parameter - Parameter X filtering Column X (integer datatype); when I pass values to Parameter X - say 1,2,3,4... individually, I am able to run the report correctly in SSRS.
However, when I try to pass a string of values - (1,2,3,4...) - i.e. (by checking) 'Allow multiple values' for this Parameter X (text datatype) in SSRS Report Parameter Properties box, I get this error -
'Cannot add multi value parameter '?' for dataset XYZ because it is
not supported by the data extension. (XYZ is the main dataset for this report)
The values 1,2,3 are passed as input from another dataset (PQR).
How can I pass multiple input values (1,2,3,...) to Parameter X from this PQR dataset ?
As I have mentioned, I cannot modify the PSQL Firebird stored procedure (main dataset XYZ) at all. The procedure reads something like this for filtering Column_X:
WHERE :Parameter_X CONTAINING Column_X
Now if :Parameter_X = 1 or 2 or 3 individually passed from dataset PQR, SSRS report works fine.
If :Parameter_X = (1 ,2, 3, ....) multi values passed from dataset PQR, SSRS report throws the above error.
I can modify the dataset PQR, but not the main dataset XYZ.
Any suggestions ?
Join(Parameters!ParameterX.Value,",") still works. In my case it was using OLE DB connection type instead of regular ORACLE in Report Manager.
It seems OLE DB could not parse Join(Parameters!ParameterX.Value,",") .

ssrs - Forward pointing dependencies are not valid

In an existing SSRS 2008 r2, report, I am attempting to add a parameter called 'Customer_Category'. I am getting the following error message:
The report paramter 'CustomerNumber' has a DefaultValue or a ValidVaue that depends on the report parameter 'Customer_Category'. Forward pointing dependencies are not valid.
I am trying to determine how to fix this error. The 'CustomerNumber' is a parameter value that is obtained by reading from a dataset. In this dataset there are existing other parameters called 'Customer_Type' and 'Customer_Preference'. Both of these parameters obtain there values from selections that the user makes when the SSRS report is executing. There are no default values.
I am trying to have the 'Customer_Category' be the same way where there are no default values and the user must select the parameter value when the report is executing. There should only be one value that the user can select from.
The new parameter called 'Customer_Category' is the last parameter in the list of parameters. Does the order of parameters make a difference? If so, how can I move the 'Customer_Category' parameter in front of the customer_number parameter?
Here is the sql that is used from obtaining a list of customers from the dataset for customer_number:-
SELECT Distinct CustomerNumber
FROM BridgeUserCustomer
WHERE
Type = #Customer_Type
AND Preference = #Customer_Preference
AND Category = #Customer_Category
GROUP BY CustomerNumber
Would you tell me what is wrong and what I can do to solve the problem?
Summary
The order of parameters in your IDE (Report Designer or Report Builder) matters.
If you have a hierarchy of parameters (one level dependent on the other), the top-level parameter must appear first in the parameter list.
In SSRS these are referred to as cascading parameters.
Solution
Open the Report Data tab
Expand the Parameters folder
Select a parameter and use the up/down arrows to adjust order
Report Designer
Report Builder

rs report design parametrized query for MySQL

I have a Mysql DB report with visual studio report server and is displaying correctly in report server.
but i want to do a parametrized query and after reading and searching i know the obdc driver cant pass # and i have to use '?' but after trying a lot i cant figured out how to implemented.
I have a #parameter which use a secodn dataset that query the db for usernames
i have my main dataset with the where (user = '?') and in the dataset parameter tab i try putting an expression with the select query for user and try use the actual parameter.
am a little lost here.
got it in my case..., use
where (usernames = ?)
in the query and in the parameters tab of the dataset use Parameter1 as name and in value match it with the created parameter in Parameters

How to pass a parameter to SSRS report from SSIS package?

I'm writing my first SSIS pkg and I'm stuck. Any insight would be greatly appreciated.
I'm running a sql agent job that kicks off a SSRS report. (The job was generated via a scheduled subscription.)
This report relies on 2 stored procs which require the parameter 'When' (date type) and it dumps a PDF of the report to a file share.
My execute sql task runs this: EXEC msdb.dbo.sp_start_job N'myJobName';
How can I pass a value for the parameter 'When' into the report?
Why do you even need SSIS for this? Set up a subscription in SSRS to export the report where you need in the format you need on whatever schedule you want. The Subscriptions in SSRS allow for parameters to be stored with the subscription as well.
I figured out how to accomplish this.
When you define the report in SSRS turn on "Report Data" view. On this view you will find a Folder named Parameters. Expanding this shows a node for each parameter. Right click and view parameter properties.
I solved my problem by selecting default values > Get Values from a query (specify Dataset and field). I set up a new db table named ReportParams.
CREATE TABLE ReportParams ( ParamName varchar(50), ParamVal varchar(50) )
This allowed me to do a
SELECT top(1) ParamVal FROM ReportParams WHERE ParamName = 'myparamname'.
By having my SSIS job inseRt the parameter name and value into this table, I'm able to pass a parameter to the SSRS report's default value.
Okay, it's somewhat kludgy, but it works. If anybody has a cleaner way to get this done, I'd love to hear it.
William - the SSIS job is necessary to fill the database with the data that drives the DataSets that the Report depends on.