Report Builder - 3 Parameters all in one Query. Forward dependencies are not valid - sql

I have an issue with building my report, I have 3 params and all 3 are in a query, they are supposed to get their values from the "drop down menus" before running the reports and are used in a where cluase to get specific stuff from the database. However I can seem to get it to work.
Example Query
Select * from [Table]
Where ID = #ID and DateFrom = #DateFrom and DateTo = #DateTo
order by ID
This is the query, I tried changing the orders of the params but it doesnt work.
Error:
The report parameter 'ID' has a DefaultValue or a ValidValue that depends on the report parameter "ID". Forward dependencies are not valid.

Based on the error you reported...
"Error: The report parameter 'ID' has a DefaultValue or a ValidValue that depends on the report parameter "ID". Forward dependencies are not valid."
I suspect your ID parameter's valid values are taken from a dataset query. The dataset query uses a parameter called #ID . You cannot populate values for a parameter if the parameter you are trying to populate is required by the query.
If you are trying to get a list of available ID's to populate the ID parameter drop down then you need to create a separate dataset for this. The dataset query would be something simple like.
SELECT DISTINCT ID FROM [Table] ORDER BY ID
You can then change your ID parameter's "Available Values" dataset to point to this new dataset.
If this does not help, show you report design (the parameters at least), the parameters properties and the dataset queries for each one. Your issue should be clear once all that is visible.

Related

How to Pass Report Parameter as if it were a Query Parameter?

I am trying to make a report that allows a user to input an ID and then check this ID against several payee tables to see if the value already exists. The code requires an input and then displays a value of 1 if the code already exists and a 0 if the code is available for use. This works in the SQL code when setting the ID as a query parameter, but does not appear to work when creating an SSRS report and passing a report parameter through; the report displays no data.
I have tried adding a tablix column to display the parameter for validation. This field remains blank when attempting to pass a report parameter, but does properly display when hardcoding the query parameter.
DECLARE #id varchar(8)
SELECT #id,
CASE
WHEN #id IN (
SELECT id
FROM payee_1
)
THEN 1
WHEN #id IN (
SELECT id
FROM payee_2
)
THEN 1
WHEN #id IN (
SELECT id
FROM payee_3
)
THEN 1
ELSE 0
END as validation
The SQL query produces the results I would like to see in the SSRS report. It simply shows the input ID and a 1 if not available (or a 0 if available). When input into SSRS, the report parameter never passes through as if it were a query parameter and my report ends up being blank.
When your report is open for edit (Visual Studio), in the "Report Data" panel (docked on the left, by default), expand "Datasets". Right-click your Dataset and choose "Dataset Properties".
In the "Dataset Properties" window, on the left, click "Parameters". The parameters shown are populated from your query. If you have a parameterized query, then this will give you the option to bind your query parameters ("Parameter Value") to your report parameters, or set up other defaults or formulas, etc.

How to give NOT NULL as a parameter value in Report Builder

I'm trying to build a report where i try to filter values from a table by their close dates (datetime). So far i've created a parameter called #closeDateParam and i want users to select between 2 options, one of them refers to NULL and other one refers to NOT NULL.
my sql is something like this,
select * from TABLE1 where TABLE1.CLOSED_DATE = #closeDateParam
and i've specified values for this parameter in parameter properties as
(Null) and (NOT Null)
but it seems it does not work for me.
I'd be grateful for any help since i'm a newbie at using ReportBuilder. Thanks for helping!

SSRS Dropdown for column items

I've built a SSRS report using a SQL query for the Dataset1. I'm trying to build a parameter that gives the users a dropdown list. I ended up creating a Dataset2 to get distinct values for the parameter Label and then use Dataset1 for the actual value (allowing for multiple values).
EDITING PER Request:
Dataset1 query:
SELECT vu_SOPWork_HistoryUnion.Type
,vu_SOPWork_HistoryUnion.SOPTYPE
,vu_SOPWork_HistoryUnion.SOPNUMBE
,vu_SOPWork_HistoryUnion.Date_Document
,vu_SOPWork_HistoryUnion.ExtendedPrice
,IV00101.ITEMNMBR
,IV00101.USCATVLS_2 AS Family
,IV00101.USCATVLS_3 AS Product
,vu_SOPWork_HistoryUnion.VoidStatus
,RM00101.CUSTCLAS
,GL00100.MNACSGMT
,vu_SOPWork_HistoryUnion.BillTo_CustNum
,vu_SOPWork_HistoryUnion.BillTo_CustName
,vu_SOPWork_HistoryUnion.sales_territory
,vu_SOPWork_HistoryUnion.ITEMDESC
FROM (
(
test.dbo.vu_SOPWork_HistoryUnion vu_SOPWork_HistoryUnion INNER JOIN test.dbo.IV00101 IV00101 ON vu_SOPWork_HistoryUnion.ITEMNMBR = IV00101.ITEMNMBR
) INNER JOIN test.dbo.RM00101 RM00101 ON vu_SOPWork_HistoryUnion.BillTo_CustNum = RM00101.CUSTNMBR
)
INNER JOIN test.dbo.GL00100 GL00100 ON IV00101.IVSLSIDX = GL00100.ACTINDX
Dataset2 Query:
SELECT DISTINCT IV00101.USCATVLS_2 AS FamilyNames
FROM test.dbo.IV00101
I would like to use the Dataset2 "FamilyNames" as the label options against Dataset1 "Family" values. Dataset2 gets the distinct values that I want to put in the drop down for the user to choose and then receive all rows that has that value in Dataset1 "Family". I'm an expert on not giving enough information. Hope this helps you help me. Thanks.
OK, do the following..
Create DataSet1 with the query as you have it now but append the following to the end of the query
WHERE USCATVLS_2 IN(#Family)
When you do this, the #Family parameter will be created automatically in your report, we'll get back to this later.
Create another dataset called Dataset2 (or a more sensible name like 'families' in this case) with the following simple query.
SELECT DISTINCT USCATVLS_2 FROM test.dbo.IV00101 ORDER BY USCATVLS_2
Edit the #Family parameter:
Set it to multi-value
Change the available values to be a query
Select your 2nd dataset as the datasource
Choose USCATVLS_2 as both the labels and values.
Create your report as normal with the tablix/matrix based on Dataset1.
Notes:
A few other things you might want to consider, but not required.
If a list of family names with some kind of ID is available in your database then I suggest you use that for your parameter list, you would also then have to edit the query in dataset1 to match. Remember that the parameter will contain whatever is in the column of the query that you chose as the value column in the dataset that populates the parameter list
Consider using aliases for table names in your queries rather than the full table names all the time, it makes the code more concise and easier to read.
Name your datasets according to what they contain or do, e.g. I would call Dataset2 'Families' or something similar as that is what it contains. When your reports get more complex it will make them easier to understand.

SSRS: When Multi-value Parameter = Select ALL remove filter in Script

I have a report that has multiple multi-value parameter. What I wanted to do is if the parameter is = Select All I'll remove that parameter to my SQL Script.
Example is I have a Product group and Product Name parameter and what I want is if the user selects all the product group my script will be like:
SELECT * FROM TABLE WHERE PRODUCT_NAME IN (#ProductName)
While if the user did not select all Product Group, my script will be like:
SELECT * FROM TABLE WHERE PRODUCT_NAME IN (#ProductName)
AND PRODUCT_GROUP IN (#ProductGroup)
I want to know how Can I detect when multi-value parameter is = Select All. I think it will really help the loading time of the tool if I just remove the filter on my script.
As far as I know, you cannot detect when "Select All" has been checked by the user.
To remove the filter completely when the user selects all the choices in a multi-valued parameter you would have to employ logic in your stored procedure that checks to see if all the choices were passed to it in the parameter, and if so, don't use the parameter at all in the main query.
You can add your own ALL value to the parameter. In the dataset query check if the user have selected 'ALL' if so don't use the parameter.
Something like this:
IF ('ALL' IN #ProductGroup)
BEGIN
SELECT * FROM TABLE WHERE PRODUCT_NAME IN (#ProductName)
END
ELSE
SELECT * FROM TABLE WHERE PRODUCT_NAME IN (#ProductName)
AND PRODUCT_GROUP IN (#ProductGroup)
It is not tested but should work
If your parameter is based on a dataset, you can compare the numbers of elements selected in the parameter vs. the number of items in the dataset for the parameter.
=IIF(Parameters!AREA.Count = CountRows("Areas"), "ALL", "Some")

For SSRS in Visual Studio 2008, how can I make a variable accept multiple values as well as a single value?

I'm making a report with Visual Studio 2008, pulling the info from a table in a database. Let's say I just want to show the Type of employee (which is represented by an int, say 1-10) and their Name. Then my dataset would be this query:
SELECT Type, Name
FROM Employees
WHERE Type = #Type
This is SSRS, so I do not need to declare or set the variable (correct me if I'm wrong). When I run the report, it will give me an option to type in an int for the Type and it will create the corresponding report. My question is how can I set it so that I can type 1,2,3 in for the Type so that I get a report with those types of employees? So having the int variable be able to accept a list of ints or just one int. Essentially the "resulting query" from that example would look like this:
SELECT Type, Name
FROM Employees
WHERE Type = 1 AND Type = 2 AND Type = 3
On the left side in the Report Data window under the Parameters folder, right click the variable, hit Parameter Properties, then check 'Allow Multiple Values' and select the correct datatype in the dropdown. I'm not sure why it decides to make a dropdown when you run the report, and you have to enter the values each on their own line instead of separated by commas, but it seems to work fine. Then just change the WHERE clause in your dataset from WHERE Type = #Type to WHERE Type IN (#Type). I don't know if the parentheses are necessary.
Also if you create a separate dataset that will present certain values you can have those show up instead of having to type them out. For example, create a dataset that contains this query
SELECT DISTINCT Type
FROM Employees
ORDER BY Type
This will create a list of distinct values for type that you can check/uncheck. You can make it more complex obviously as well.