Kajah User
Kajah User

Reputation: 591

how to pass null value when the parameters are left in empty

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?

Upvotes: 1

Views: 23372

Answers (2)

SarekOfVulcan
SarekOfVulcan

Reputation: 1358

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;

Upvotes: 4

craig
craig

Reputation: 26262

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.

Upvotes: -1

Related Questions