Non mandatory parameter in pentaho report designer - pentaho

I want to add a non mandatory parameter in pentaho report designer.
i.e. if the parameter is provided the same should be used in where clause else should not be used in the where clause of the query.
Please help me if this is feasible and if yes, then how to do it.
Thanks,

You can do this using the query itself.
In Postgres I use,
WHERE resourcename IN (SELECT CASE WHEN(${agent}::text = '' OR ${agent}::text IS NULL) THEN resourcename ELSE ${agent}::text END)
Here ${agent} is your parameter if they does not select or if left blank (if the display type is a 'Text Box') this query will give you the normal result else it will return what is provided in the parameter.

Related

SSRS: CASE WHEN NULL

I'm trying to import data from a table into my SQL Report Builder report.
In this particular column, the data will either be someone's name or "NULL".
I want to set my field to change NULL to "Other", but leave it how it is if it contains a name.
I know I must be close with what I have below, but I can't figure out how to get it to not alter the value if it's NOT NULL:
CASE WHEN ([Reviewed_By] IS NULL) THEN 'Other' ELSE '' END AS [Reviewed_By]
Obviously, with how it's written here, it will convert any name to a blank but I can't figure out the correct logic to get it to "skip" the line-item if it's a valid name.
Any help is appreciated!
Let me know if you need any other information.
Thanks in advance,
Cameron
you could just do ...
SELECT
ISNULL([Reviewed_By], 'Other') AS [Reviewed_By]
FROM myTable
To answer your question for the SQL side.
CASE WHEN [Reviewed_By] IS NULL THEN 'Other' ELSE [Reviewed_By] END AS [Reviewed_By]
Report builder has functionality to do this as well with expressions.
You can read more here 32716829/if-value-null-then-else-value-ssrs-expression-issues.

How can I add a where statement on list conditionally in report query?

How can I add a where statement in iReport query with a condition that a list is not empty:
WHERE
CASE WHEN length($P{list}) > 0 THEN table_x.id IN ($P!{list}) END
I tried to display the report passing an empty list, but it does not work.
Jasper report has it's own query system and I presume your $P{list} is a class that extends java.util.Collection for example a java.util.List, since you state "passing an empty list"
To create a prepared statement IN query on Collection in jasper report you use:
WHERE $X{IN, table_x.id, list}
Do note that if list is null or it is an empty list this query will return all records, see using-parameters-queries
JasperReports handles special characters in each value. If the parameter is null or contains an empty list, meaning no value has been set for the parameter, the entire $X{} clause is evaluated as the always true statement “0 = 0”.
To not show any records, you need to add at least one null value to the List in java before you pass parameter to jasper-report.
if (list.isEmpty()){
list.add(null);
}
Please also note that you should avoid using $P!{param} since this creates
an sql through string concatenation an open your application to SQL injection attacks, always try to use prepared statement instead.
Your ELSE clause is NULL, and that is false. I would recommend avoiding the CASE:
WHERE length($P{list}) = 0 OR table_x.id IN ($P!{list})
If i understood correctly, try using this:
WHERE (CASE WHEN length($P{list}) > 0 THEN table_x.id IN ($P!{list}) END) <> ''

Validation? Yes or No, otherwise Error. SQL

I'm trying to add to current query where a certain field name must contain either 'Y' or 'N'. I'm currently using substrings and isnumeric functions to manipulate the data within.
Here is an example:
(
LEN(STERLING_RETURN_SIGNAL) > 1
or ISNUMERIC(substring(STERLING_RETURN_SIGNAL,1,1)) = 1
)
So the STERLING_RETURN_SIGNAL, must either be 'Y' or 'N' otherwise +('Error message').
Many thanks. Using Sql Server Management Studio.
Please note, I am a beginner...
select
case
when
STERLING_RETURN_SIGNAL in ('Y','y','N','n')
then STERLING_RETURN_SIGNAL
else
'Invalid value for signal'
end as signal
from ...

Incompatible data types in CASE STATEMENT

I am converting a SAS code into Cognos Report Studio version 10 where am stuck at a point where there is data formatting needed.
IF SDW_STAT ^= '' THEN PRINCIPAL_BAL = TOT_PRIN;
Where '' represnts single quotes without any space
I tried writing a CASE STATEMENT:
CASE
WHEN ([SDW_STAT] IS NOT MISSING) THEN ([PRINCIPAL_BAL] = [TOT_PRIN])
ELSE ('')
END
I also tried couple of options like <> '', is not null, <> ' ' instead of IS NOT MISSING but none of them worked. Can you please suggest where I am going wrong?
Pls note: SDW_STAT column has few blank fields and some characters like 'Y' 'S' etc.
Try putting the column outside of the CASE statement:
PRINCIPAL_BAL =
CASE
WHEN COALESCE(SDW_STAT,'') <> '' THEN TOT_PRIN
ELSE PRINCIPAL_BAL
END
Logically, this will update the principal_bal to tot_prin when sdw_stat doesn't equal blank or null. If it is blank, then it will just update it to itself.
The problem is likely the ELSE statement. Your THEN clause is an equation. This will return a boolean, either true or false. Your else is returning a string. These types aren't compatible. You can test this by changing your ELSE to:
ELSE (false)
My guess is the data type error will go away.
Can you elaborate on where you are using this code? Is it in a data item or in a filter? There are different rules depending on where your expression is used.
Note: I would comment on the question directly but I'm new and don't yet have the ability.

How to create list as a parameter in SSRS?

I have a report in 2005 SSRS which I want to add a parameter to. The parameter would be comprised of a group of zip codes, but be selected as a single item in the list.
For example, I would like to have 5 zip codes as one selection in the list and 3 for another, etc:
Select 11111,22222,33333,44444,55555,66666 AS Boondock
Select 77777,88888,99999 AS Timbuck
Select Zip Codes NOT IN (11111-99999) AS Everything Else
So my selections in the dropdown would be:
Boondock
Timbuck
Everything Else
Can anyone help me with how I should go about creating this parameter?
Create a simple string parameter to present to the user. Let's call it ZipCodeSet.
Create a dataset that examines the #ZipCodeSet parameter and returns the appropriate list of zip codes. Call it ZipCodeSelection.
Create an internal multivaue parameter that uses ZipCodeSelection as both its Available Values and Default Values. Call it SelectedZipCodes.
Use SelectedZipCodes in your report's datasets.
The easiest solution here would probably to use a Calculated Field on your dataset, called LocationDescription, for example:
=SWITCH(Fields!ZipCode >= 11111 and Fields!ZipCode <= 66666, "Boondock", Fields!ZipCode >= 77777 and Fields!ZipCode <= 99999, "Timbuck",True, "Everywhere Else")
The lone true statement at the end is due to the SWITCH expression reading left-to-right and exiting once it evaluates one of the switches as TRUE. This way for each of the items in your table of ZipCodes you will always end up with a TRUE result.
I assume you're evaluating a range of ZipCodes, and not exact values of 11111,22222, and so on? If so, the switch will have more values. A sample of your data would help if you want an exact answer.
Once you have built your Calculated Field, you can then set up a Parameter (called #LocationParameter) with available values based on a query of your LocationDescription field, then just filter your dataset using:
Expression:
= Fields!LocationDescription
Operator: =
Value:
#LocationParameter
(if you want multiple selections on your parameter, change the operator to IN)
Hope that helps.