I am developing a Crystal Report from the database, and am setting a parameter's value in Crystal Reports itself, with a Command object. My issue is that when I run the Crystal Report, if I leave any parameter as null, it will return all the records from the database. How is that possible?
If you're using parameters in a Database Command, you can't use optional parameters. However, if you're using CR2008 (I think that's when they were added), you can set your parameters as optional, and then use the HasValue() function to see if the user selected a value.
RecordSelection:
If HasValue({?MyParm}) Then
{Command.MYFIELD} = {?MyParm}
Else
True;
Crystal Reports requires each Parameter Field to have a value; nulls aren't allowed.
If you are using a Command object, you will need to use syntax like this in SQL:
--t-sql syntax; assumes numeric value and -1 is the value chosen to represent 'all values'
WHERE table.field = CASE
WHEN {?command_object_prompt} = -1 THEN table.field
ELSE {?command_object_prompt}
END
If you are using 'standard' database linking (as opposed to a Command object), look at my posting Crystal Reports: Optional-Multi-Select Parameters.
Related
First off this is my first attempt at a multi select. I've done a lot of searching but I can't find the answer that works for me.
I have a postgresql query which has bg.revision_key in (_revision_key) which holds the parameter. A side note, we've named all our parameters in the queries with the underscore and they all work, they are single select in SSRS.
In my SSRS report I have a parameter called Revision Key Segment which is the multi select parameter. I've ticked Allow multi value and in Available Values I have value field pointing to revision_key in the dataset.
In my dataset parameter options I have Parameter Value [#revision_key]
In my shared dataset I also have my parameter set to Allow multi value.
For some reason I can't seem to get the multi select to work so I must be missing something somewhere but I've ran out of ideas.
Unlike with SQL Server, when you connect to a database using an ODBC connection, the parameter support is different. You cannot use named parameters and instead have to use the ? syntax.
In order to accommodate multiple values you can concatenate them into a single string and use a like statement to search them. However, this is inefficient. Another approach is to use a function to split the values into an in-line table.
In PostgreSQL you can use an expression like this:
inner join (select CAST(regexp_split_to_table(?, ',') AS int) as filter) as my on my.filter = key_column
Then in the dataset properties, under the parameters tab, use an expression like this to concatenate the values:
=Join(Parameters!Keys.Value, ",")
In other words, the report is concatenating the values into a comma-separated list. The database is splitting them into a table of integers then inner joining on the values.
I have this report parameter, named #LeadSource2.
Will it work when I pass it to my final SP that will use in (#LeadSource2) in the code…?
I don’t understand if Stored Procedures do not accept multiple values for a parameter, why SSRS has the option to pass multiple values?!
I have it like this on my report:
And in my SP I do 'where LS in (#LeadSource2).'
Its not showing me results, so I think it does not work…
My question is why SSRS would allow me to do that if the SP wouldn’t accept it?
If you were using the in(#LeadSource2) syntax in a direct SQL dataset, it would work fine. Whereas because you are using a sproc, as Dan says, you will need to be more involved.
Use the join expression in your Parameter Values properties window to pass your multi-select values to your sproc as a comma/pipe/whatever separated list and then use a string splitting function to parse it out into multiple values you can use in your sproc.
I my web application I am using I-REPORT designer for designing report.
For the data used in report,I have written a query that fetch two column values from different table.Here data type of column data is real.In ireport corresponding data type is Float.
Here,if one of the data have a value,other have a no value or empty.So I have to display a value that is not null or empty using text field,when the report is generated.So I have implemented condition in text field
( $F{permit_quantity}==null ?$F{fst_insp_qpqlml_quantity} : $F{permit_quantity} )
Here the fields $F{permit_quantity}, $F{fst_insp_qpqlml_quantity} corresponding to two column values returned by query.
But the above condition is not working when $F{permit_quantity} is empty or null.
I am using postgresql database
You can try to use .equals() Method if the condition itself is not working.
$F{permit_quantity}.equals(null) ? $F{fst_insp_qpqlml_quantity} : $F{permit_quantity}
There could be various other reasons why your code doesn´t work but I can´t tell from your snippet.
$F{permit_quantity}.toString() == null ? $F{fst_insp_qpqlml_quantity} :
$F{permit_quantity}
This solves your problem.
I have 3 multivalued parameters in my report.Out of them 2 are optional.
Is there any way to get the results in the report with out selecting any from the 2 optional parameters.
My stored proc checks the mulivalued parameters as (States IN (SELECT * FROM Split(#State,',')))
I have done this for a single valued parameter with WHERE CustomerId = #CustId OR #CustId IS NULL.
WorkAround:
I selected 'Allow null value', it is throwing this error
"A multi-value parameter cannot include null values"
Can anyone point me in the right direction?
Have a look at this article on Passing Multivalued parameters.
Basically the above link contains a workaround to meet your requirement for an optional multivalued parameter. The steps to achieve this are as follows:
Replace "ALL" with " " (BLANK) in the parameter's dataset query.
Assign -1 as default parameter value for your multivalued parameter.
I have a dataset referencing a proc. That proc takes in a #UserName
In my parameters of my dataset, I have specified a new param called #UserName and for its default value the expression =User!UserID but I still get this error when the report tires to render:
The default value expression for the query parameter #UserName contains an error [BC30654] 'Return' statement in a function, Get, or Operator must return a value
The only thing I can think of is that instead of modifying the existing datasource I had defined in the report, I removed and added a new datasource. I hope that doesn't matter as long as there is a valid data source for the report to go on that has those fields...I just switched this report to reference a copy of our current database for testing purposes.
Sounds like the report parameter is not being passed to the stored procedure.
In the Dataset Properties, click on the Parameters tab and check that the stored proc parameter #Username is correctly mapped to the Report parameter #Username.