Select Expert - results changing

Printed From: Crystal Reports Book — Forum Name: Technical Questions

I am running into a problem =- where my select expert changes based on which part of the query I bring to the top. I do have several dynamic parms which bring back fairly large list of items to select from (3 pages).   Then I base the query off what the user selects in those and other parms.

Here is they query

if {?Client}<>"*ALLCLIENTS" then {Client.DISPLAY_NAME}={?Client} else true and
if {?Location}<>"*ALLLOCATIONS" then {Location.DISPLAY_NAME}={?Location} else true and
if {?Impact Type}<>"*ALLIMPACTS" then {CVGCPLIMPACTM1.TYPE} = {?Impact Type} else true and
if {?Ticket Type}="Change" then {CVGCPLIMPACTM1.NUMBER} startswith "C"
else if {?Ticket Type}="Incident" then {CVGCPLIMPACTM1.NUMBER} startswith "IM"
else if {?Ticket Type}="Problem" then {CVGCPLIMPACTM1.NUMBER} startswith "PM"
else true and
if {?Program}<>"*ALLPROGRAMSS" then {Program.DISPLAY_NAME}={?Program} else true and
date({@relevant_date}) in {?DateRange} and
not {@nulldatecheck}


So - as it stands the "date" part doesnt work - but when I move that to the top - then it works (and something under it doesnt filter).   Anyone ever have strange results like this? Anyone found a solution.

Thanks in Advance - this one has me very stumped.
So do you want the data filter to be part of the else clause? if so you will need to put the Else clause criteria inside of parenthesis.  Also the text is difficult to read.  I suggest indenting embedded if statements.
To add ...
you don't need the if-then, just stick with true false conditions.
Also if you are dealing with NULLs you either need to set the formula to using default values for nulls or use the null condition first, otherwise the row will not evaluate when it hits the null. Even if you set the formula to use defaults for Nulls you can still explicitly look for them in the formula

(not ({@nulldatecheck}))
AND
({?Client}="*ALLCLIENTS" OR {Client.DISPLAY_NAME}={?Client})
and
({?Location}="*ALLLOCATIONS" OR {Location.DISPLAY_NAME}={?Location})
and
({?Impact Type}="*ALLIMPACTS" OR {CVGCPLIMPACTM1.TYPE} = {?Impact Type})
and
(
     ({?Ticket Type}="Change" AND {CVGCPLIMPACTM1.NUMBER} startswith "C" )
     OR
     ({?Ticket Type}="Incident" AND {CVGCPLIMPACTM1.NUMBER} startswith "IM")
     OR
     ({?Ticket Type}="Problem" AND {CVGCPLIMPACTM1.NUMBER} startswith "PM")
)
AND
({?Program}="*ALLPROGRAMSS" OR {Program.DISPLAY_NAME}={?Program})
and
date({@relevant_date}) in {?DateRange}


Edited by DBlank - 08 May 2018 at 7:54am
Thanks so much for replying - VERY MUCH appreciated.

Do others find that the select expert likes to move things around on you - and doesnt always keep things how you entered them.

In any case - I'm still testing - but I think the advice is working   
As an FYI _ here is what it ended up with....

({?Program}="*ALLPROGRAMS" OR {Program.DISPLAY_NAME}={?Program}) and
({?Client}="*ALLCLIENTS" OR {Client.DISPLAY_NAME}={?Client}) and
(
Select {?Ticket Type}
Case "Change": {CVGCPLIMPACTM1.NUMBER} startswith "C"
Case "Incident": {CVGCPLIMPACTM1.NUMBER} startswith "IM"
Case "Problem": {CVGCPLIMPACTM1.NUMBER} startswith "PM"
Case "*ALLTYPES": true
) and
not {@nulldatecheck} and
{@relevant_date} in {?DateRange} and
({?Location}="*ALLLOCATIONS" OR {Location.DISPLAY_NAME}={?Location})

Edited by GregF - 09 May 2018 at 8:51am
To your question, yes i do see the order in which I add conditions get swapped around in the actual SQL.

Glad you got it sorted out