Author |
Message |
DrPepperholik
Newbie
Joined: 03 Apr 2014
Online Status: Offline
Posts: 9
|
Topic: Select all when parameter is blank. Posted: 04 Apr 2014 at 2:37am |
Hi all, I need some help with record selection. I need Crystal to select all records if this one parameter is blank, otherwise select where the record is equal to the parameter. It sounds simple but I've tried suggestions I've searched for but they didn't work.
What keeps happening is the SQL string gets appended with this if I send in a blank:
"Table"."Column"=''
It works fine if I send in a parameter.
Right now I have this:
(if (NOT isNull({?Parm})) then {Table.Column} = {?Parm})
Which gives me the SQL above.
|
IP Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
Posted: 04 Apr 2014 at 4:00am |
I assume you have a version of Crystal that allows for null parameters...
(NOT(hasvalue({?Parm})) or {?Parm}={Table.Column})
|
IP Logged |
|
DrPepperholik
Newbie
Joined: 03 Apr 2014
Online Status: Offline
Posts: 9
|
Posted: 04 Apr 2014 at 4:06am |
I'm using version 14.
That didn't work. I still have the "Table"."Column"='' showing up in my SQL Query and no data.
|
IP Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
Posted: 04 Apr 2014 at 4:36am |
what exactly are you putting in the select statement?
|
IP Logged |
|
DrPepperholik
Newbie
Joined: 03 Apr 2014
Online Status: Offline
Posts: 9
|
Posted: 04 Apr 2014 at 4:58am |
This is the record selection:
(if {?Parm1?} = 'Y' then {SomeTable&Col} ='Y' else 1=1) and
(if {?Parm2}='N' then {SomeTable&Col}='P' else 1=1) and
{SomeTable&Col} = {?Parm3} and
{SomeTable&Col}>={?Parm4} and
{SomeTable&Col}<={?Parm5} and
{SomeTable&Col} in {?Parm6} to {?Parm7} and
(NOT(hasvalue({?Parm})) or {?Parm}={SomeTable&Col})
This is the SQL it generates:
SELECT Stuff
FROM Location
WHERE "SomeTable&Col"='P' AND "SomeTable&Col"=44 AND ("SomeTable&Col">={ts '1950-01-01 00:00:00'} AND "SomeTable&Col"<{ts '2050-12-02 00:00:00'}) AND "SomeTable&Col"=6093 AND "SomeTable&Col"=''
ORDER BY "SomeTable&Col", "SomeTable&Col", "SomeTable&Col", "SomeTable&Col"
Where Parm = blank
Edited by DrPepperholik - 04 Apr 2014 at 5:03am
|
IP Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
Posted: 04 Apr 2014 at 5:20am |
are param 1 and 2 set up to not allow nulls and what is the input type? a string, a drop down,...? I do not recomment uinsg the if-then process in the select criteria but am not clear on the set up so am not sure how to recommend to change it.
did you remove all of your other criteria to see if the
(NOT(hasvalue({?Parm})) or {?Parm}={SomeTable&Col})
works as desired by itself?
When running the report are you selecting the null check box for that parameter?
|
IP Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
Posted: 04 Apr 2014 at 5:22am |
I see you revised your post.
Are you selecting a 'blank' ("") value from a parameter list or are you setting the param value to NULL using the null check box in the parameter pop up?
Edited by DBlank - 04 Apr 2014 at 5:23am
|
IP Logged |
|
DrPepperholik
Newbie
Joined: 03 Apr 2014
Online Status: Offline
Posts: 9
|
Posted: 04 Apr 2014 at 5:27am |
Parm 1 is not allowed to be null. Parm2 can be. The input type is number for Parms 1, 2 and 3.
Removing all other selection criteria still yields the same SQL with the WHERE SomeTable&Col = ''.
There is no option for a null check box. Should there be one?
EDIT to answer last question: There is no null option, I'm just leaving the field blank, there aren't any options. It's just a text field that I leave blank.
Edited by DrPepperholik - 04 Apr 2014 at 5:29am
|
IP Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
Posted: 04 Apr 2014 at 6:05am |
I am not using version 14 but I believe it has the option for each of the parameter set ups to allow you to set to null or not ... equates to the hasvalue() in the formula).
you can try this...
({?Parm}="" or {?Parm}={SomeTable&Col})
I am not sure if it wil work or not as the hasvalue is where I have seen this done in versions passed XI.
|
IP Logged |
|
DrPepperholik
Newbie
Joined: 03 Apr 2014
Online Status: Offline
Posts: 9
|
Posted: 04 Apr 2014 at 6:55am |
The only problem with {?Parm} = "" is that the DB value I'm checking for will never be blank.
I've seen the check box for null before in some reports. I'm not sure why this one doesn't have it.
The report I've seen that has the check box for null values uses a stored procedure instead of linking to the views directly. Could that be why it allows for a null but this one doesn't give me the option? There isn't any settings in the parameter that indicate to allow null value.
Edited by DrPepperholik - 04 Apr 2014 at 7:01am
|
IP Logged |
|
|