parameter value gets reset and multi-value parameter doesn't work - sql

Two Issues:
I've set the value of a Date parameter (Start Date) when moving from the home screen (Report 1) to the next screen (Report 2) as the first day of the current year. In report 2, if I try to change the Start Date to another date, it gets reset to the first day of the year. I had the default value set as the first day of the year and even after removing it, the Start Date gets reset.
I've set a multi-value parameter (Area) in Report 1 that collects four integers. I pass Area to Report 2 (through Join (Parameters!Area.value,",")). I also used SPLIT (Join (Parameters!Area.value,","),",") to get the value. Then, in the data set, I call this parameter as "Select A1,A2,A3,B1,B2,B3 FROM TEST_VIEW WHERE ID IN (?)". But this query throws an error that the query could not be executed. I ran the same query on the server side and it runs fine.
Note:
We cannot reference parameter names as #area for example because the Composite Server doesn't allow that.
Split and Join operate on strings but my parameters are of integer type. Is this an issue?
Please help.

Re #2:
Few things to answer and work through here. First of all, JOIN can operate on integers as it returns a string value while SPLIT cannot operate on an integer as it operates on a string (needs a string to "split"). I'd suggest that the JOIN/SPLITS are necessarily complicating what you are trying to do, although they should still work in this scenario.
Try just passing your multivalue parameter to Report2 from the parent report as Parameters!Area.Value (no joins) and then catch it on report2 again with a multivalue integer parameter. SSRS will automatically handle the multi-value passing between reports and then your query should work.
Note that JOIN/SPLIT is necessary if you want to send a multivalue parameter to a SQL stored procedure for data retrieval, but you have to perform the split on the SQL side.

Related

SSRS Parameter That Queries ALL When NULL and Can Query on MULTIPLE Values Without Options Listed

I have a business requirement that requires a user to be able to search for many different order numbers and be presented with additional information through my report. Since we have a very large amount of orders on any given day, I want them to be able to copy and paste the list into the SSRS Parameter (which I have setup fine now). I also want them to be able to run the report 'wide open' and have them be able to leave the parameter blank and return all orders.
I have achieved this in the past while using 'Available Values' for the parameter. But, now that I am doing it manually, I am coming across a lot of pesky errors.
I believe I am close.. I have the following simplified query:
SELECT
AssignmentNumber,
OrderNumber
FROM
tables.Activity
WHERE
((OrderNumber in (#P_ORDER_NUMBER)) or (#P_ORDER_NUMBER = ''))
When I run this, I have success in 2 of 3 scenerios
When #P_ORDER_NUMBER is left empty, it returns all orders
When a SINGLE order is provided, it returns assignments on that order
The final issue is getting it to work with multiple Orders. I am getting an Error in SSRS reading 'An Expression of Non-Boolean type specified in a context where a condition is expected, near ','.
I assume there's in issue in the OR clause that I have.. but I haven't been able to find a workaround that meets the business need. Any ideas? Thank you!!
The following is not perfect, as it won't work if some orders are selected and then the report is re-run with no orders selected but is might be OK for your needs...
Add a new parameter to the report, I called it pBlank in my tests. You can set this to hidden once the report is complete. In the default value I used the following expression.
=IIF(LEN(Parameters!P_ORDER_NUMBER.Value(0)) = 0, 1, 0)
So it will be 1 if the order parameter is empty or 0 of it is not empty. It does this by checking the length of the first value. This is assuming the user does not have add a blank value as the first value, if they do then you could do something similar by checking the .Count property too.
Then just change the dataset query to something like
SELECT
AssignmentNumber,
OrderNumber
FROM tables.Activity
WHERE (
OrderNumber in (#P_ORDER_NUMBER)
OR #pBlank = 1
)
It may just be hung up on the empty string concept. Try allowing the parameter to be NULL - the user will get a little checkbox that says "null" - and for the parameter prompt say
Enter order number(s) or check "null" for all:
Change your query to ...or (#P_ORDER_NUMBER IS NULL)
This has always worked for me. HTH

SQL Query result and SSRS result dont match

I have created a SQL that can pass in multiple parameters and more than one condition.
Example
SELECT *
FROM movement
WHERE Arrivalid IN (#ArrivalID) OR DepartureID IN (#DepartureID)
With this script, SELECT * FROM movement WHERE Arrivalid IN ('A_1234') OR DepartureID IN (''), i am able to pull out record from SSMS.
However, when I run it in SSRS, SSRS return me empty record.
Btw, the query is created as Dataset in SSRS.
Is it a must to pass in 2 parameters? But I have already set "allow blank value ("")".
Report Parameter Properties1: https://i.stack.imgur.com/9AJwO.png
There is no filter created on this simple table format.
SSRS Report
Does anyone have any idea what has gone wrong with my SSRS setup?
To add on:
In Dataset properties, i have added "Spilt" for multiple parameter.
Expression for parameter
Setting for Default Values
Parameters - Default Value
Assuming you want to be able to enter either arrival or departure IDs then you should be able to just do this...
SELECT *
FROM movement
WHERE (Arrivalid IN (#ArrivalID) OR #ArrivalID IS NULL)
OR (DepartureID IN (#DepartureID) OR #DepartureID IS NULL)
Try setting default value for that parameter:

Why can't Aggregate and lookup functions be used in query parameter expressions in SSRS?

I'm using an if to run one query if the user selects all from a multivalued parameter, and the other if not. So I figured I'd compare selected parameters vs rows in the data set.
However I get this error:
“The expression used for the parameter 'DataSet2' in the dataset
'DataSet2' includes an aggregate or lookup function. Aggregate and
lookup functions cannot be used in query parameter expressions.”
Here's the part giving the issue:
IIf(Parameters!SomeOptions.Count < COUNTROWS("SOME_LIST"), ….
Of course supplementing the COUNTROWS("SOME_LIST") with 15 (the value it returns)works fine.
Anyone know why this happens, and/or any work around?
Here's a workaround I use in the absence of an IsSelectAll flag:
Add another internal parameter called InternalParameter_SomeOptions.
Set the default value and available values to equal the same data set as SomeOptions.
Set your expression to =IIF(Parameters!SomeOptions.Count <> Parameters!InternalParameter_SomeOptions.Count, nothing, Join(Parameters!SomeOptions.Value, "|"))
If you have a multi-selection parameter whose data source is a dataset and you want to know if ALL was checked, from within your REPORT Dataset (like an SQL) to filter properly, look no further!
Why does this matter? Say you have a dataset (love datasets as data source for parameters btw, save em on the server for reuse over and over) for displaying a vendor list for users to select one or more (multi) from. What if that list is 10,000 long. You do NOT want to use: WHERE VENDOR_ID IN(#VENDOR). If the list is long enough, it WILL bomb and you will have to hunt the error down in SSRS log. So, this is one reason why we need to check if ALL was selected.
Create a new parameter identical to the dataset parameter(so they both use the same dataset and have the same default values), make sure to set it to multi selection and hidden (you do not want users seeing it). I name mine ---All where --- is the name of my parameter to easily distinguish.
For the dataset that serves as your REPORT data, add an additional Parameter. I like to call it #Is----AllChecked where ---- is the name of my parameter. It is named as a boolean (1 for true, 0 for false). In this example, it would be named #IsVendorAllChecked.
In the DEFAULT value expression check if the count of each REPORT parameter is the same (the one the users use and the duplicate), and return a value, like 1 if the same 0 if not. For example =IIF(Parameters!Vendor.Count = Parameters!VendorAll.Count, 1, 0)
In your REPORT Dataset, evaluate the parameter value and act accordingly in your SQL: where ( (#IsVendorAllChecked = 1 and vendor_id = vendor_id) or (#IsVendorAllChecked = 0 and vendor_id in(#Vendor)))
#Vendor obviously being the parameter the user interacts.
Always wanted to contribute.
SE: Report Builder check if all was selected
SE: Report Builder how to check if all was selected
SE: Report Builder parameter query expression cannot use aggregates

How can I run a query passing information from a form?

I guess this is a silly question, but I'm having problems figuring this out.
I have two tables with loads of information used to make reports.
I have a query that joins these two tables.
The same query adds two simple filters: A date range and an ID checker.
The reports are supposed to be printed withing a date range with a specific ID.
Every time I need to change the query data range I need to manually edit it and change the parameters.
How can I make a form and pass this information to the query so I won't have to manually update the query every week?
I made a new form with two date fields and I would need some code to pass this information to the query before opening it, but DoCmd.OpenQuery Method doesn't permit I pass any information.
Ideally I'd prefer to use a SQL command to set the query and then open it, is this even possible?
Actually, I am using this method often:
Declare variables in a Module and write a function for each one that simply returns the value. You can then use the function call within the Query-Designer (e. g. criteria = Between getMyValue1() AND getMyValue2())
You can then set the global variables before opening the query.
(This has worked better for me than Query-Parameters or direct references to form fields within queries.)
You could also put a condition in your query that refers to a field in your form:
SELECT ... WHERE ID = [Forms]![FormName]![TextField]
Open the report with a filter:
Dim sWhere as String
sWhere = "Tbl_Swift.Data >= #10/01/2012# AND Tbl_Swift.Data <= #10/10/2012#"
DoCmd.OpenReport "rptMyReportName", acViewPreview, ,sWhere
(I'm not sure if "BETWEEN" will work or not, although I think it should if you'd write it properly.)
You have two options.
Do not put values of parameters in the query. Access will always ask for these values on every execution of query.
use DATE() function to get the current date and calculate the week start and end accordingly. This way, you will never have to provide the date.

SSRS report not displaying data

I have just created an SQL Server 2005 SSRS report and the data is not being displayed in the Preview pane.
The dataset is correctly populated from a stored procedure against a String parameter. I can execute it in the Data pane. When running the report in the Preview pane the correct number of rows are displayed but the contents of the cells do not contain any data
The source dataset is based on a Stored Procedure with a passed in String parameter in SQL Server 2005 that return the contents of a temp table. The dataset then maps the fields to locals. I can execute this correctly in teh Data view.
Stored Procedure
ALTER PROCEDURE spWebReportStage25BuildReview
#BuildNumber as nvarchar(50)
Temp table schema
CREATE TABLE #tmpModelZones
(
BuildID bigint NOT NULL,
BuildNo nvarchar(50) NOT NULL,
ModelID int NOT NULL,
ModelName nvarchar(50) NOT NULL,
ZoneID int NOT NULL,
ZoneName nvarchar(50) NOT NULL,
SortOrder int NOT NULL,
Created bit DEFAULT 0 NOT NULL,
Closed bit DEFAULT 0 NOT NULL,
PRIMARY KEY (BuildID, ZoneID)
)
SSRS Dataset
SSRS Dataset mapping
SSRS Dataset Parameter
Executing Dataset with parameter
There are no additional grouping, filters or aggregation on the displayed table. It is simply a flat table
Never seen this before. However, SSRS can be a bit "off" at times, so here's a list of things to try. I'm afraid most of these are of the type "Have you tried turning it off and on again?".
Delete the .data files associated with the report.
Duplicate/back-up the report, and try to add the dataset in a fresh, basic tablix to see if that does show data.
Check the hidden property. Don't forget that (for some stupid reason) it's not (like in any other sane product) a Visible Y/N field, but a Hidden Y/N field.
Double check font color and size, etc.
Run the report on your reportserver (as opposed to the preview) to check if that does work.
Use some temporary text boxes to show the actual values of your parameters, to check if they are exactly the same as when you test-run the data set.
Check the code-behind (xml in the rdl) for unexpected filters, hidden property, expressions, etc. in the tablix. Even if you can't quite "read" the RDL, with syntax highlighting you should be able to skim it and extract a lot of info on this.
Check the ExecutionLog2 and other logging stuff to see how many rows are being returned in report runs.
In addition, it would help if you update/edit your question with some more info:
What kind of groupings does the tablix have?
What are the filters on the tablix, row groups, and column groups?
What is the general structure of the dataset, and it's results?
How are the parameters structured and used?
When using temporary tables, SSRS fails to get the metadata. So there are basically 2 ways of letting SSRS know the column names:
Add SET FMTONLY ON. This will retrieve the metadata but it won't display the data.
Go to the DATA tab and click on the Generic query designer and click refresh fields. This will prompt a dialogue box for specifying the parameter value. When we run the query in query designer SSRS gets the schema and the data from the stored procedure. Now the data will be available in preview pane.
I also had a similar issue. In my case, it even occurred without any parameters or anything, just the most simple report you can imagine. It included a table with a single field, no filters were used. I did manage to view some data, but only those lines were shown which did not fit into the cell and thus forced the row height to increase.
My fix for this issue: changing the font or the font size from the standard (size 10, Segoe UI). Then, all data was showing. Changing this back to Segoe UI made the data disappear once again.
I had the same problem. Here is what I found. Here is my code:
DECLARE #tblPigProblems TABLE (
Id INT IDENTITY,
PPId INT,
GaugeColor VARCHAR(25),
FullStartTime VARCHAR(25),
PigSystem VARCHAR(25)
)
IF (1 = 0)
BEGIN
SELECT * FROM #tblPigProblems
END
...
SELECT '#tblPigProblems' [PigProblems],
#p_vchLine [Line],
GaugeColor [Product],
FullStartTime [Start Time],
PigSystem [Pig System]
FROM #tblPigProblems
What I did was to use the initial "SELECT * FROM #tblPigProblems" to ensure that if any error messages were specified in the code before the final select statement returning the dataset, that SSRS was able to determine the fields from the stored procedure. Then, when the results were determined, I assigned an alias to the fields. The problem was that the aliases for the fields did not match the declared field names (ie: the declared field "GaugeColor" did not match the alias "[Product]" I supplied in the select to create the result set. The way that I realized this is that when I refreshed the fields in the Data section of the SSRS report, then displayed the dataset fields, it listed the field names from the table declaration (ie: "GaugeColor"). When I executed the stored procedure within the dataset (clicked on the !), the result set listed in SSRS showed the field aliases (ie: "Product"). Since these didn't match, nothing was displayed in the textbox I had assigned the field to (ie: "=Fields!ColorGauge.Value"). SSRS did not pick up this discrepancy and allowed the report to be created, but no values to be displayed. The fix was simple, replace:
IF (1 = 0)
BEGIN
SELECT * FROM #tblPigProblems
END
with:
IF (1 = 0)
BEGIN
SELECT '#tblPigProblems' [PigProblems],
#p_vchLine [Line],
GaugeColor [Product],
FullStartTime [Start Time],
PigSystem [Pig System]
FROM #tblPigProblems
END
Dan
I had a case where a working report stopped displaying data. I added another table with no formatting, linked to same dataset - verified that the query no longer returned data when passed parameters by SSRS. After investigating, I noticed that my test parameter for a "anchor date" value was formatted as YYYY-MM-DD, and in my updated query, I was making assumptions about the order of the characters in the date parameter (to truncate to YYYY-MM for one join).
I suspected that SSRS may be passing the date in a different format (MM/DD/YY being my current cultural setting for date defaults). So running with that hunch, I changed my SQL logic to work with any date format passed. - e.g. left(convert(date, #anchorDate, 20), 7)
This fixed my problem - the format assumptions that I had tested with (hard coded values to test the query while developing) were bad assumptions. SSRS can pass data in local formats as well - so be sure to watch out for this kind of assumption.
I had the same problem and I tried to check the priorities of my tablix. I solved the problem by changing CANGROW value to FALSE.