Search code examples
crystal-reportscrystal-reports-2008

Searching by date criteria OR Logic


Here is what I am looking to do: I currently have a report that I need to be able to search on either the post date or the admit date and the location. So for this logic I have something like this. The problem I get right now is that I get errors because date fields and not strings. Is there a way I modify this to work? Thanks!

({HSP_TRANSACTIONS.TX_POST_DATE}  in {?Start Date} or
({?Start Date} = '' and not isnull({HSP_TRANSACTIONS.TX_POST_DATE}))) and

({HSP_ACCOUNT.ADM_DATE_TIME} in {?Admit Date} or
({?Admit Date} = '' and not isnull ({HSP_ACCOUNT.ADM_DATE_TIME}))) and

(If {?Location} = "X" then ({HSP_ACCOUNT.ACCT_CLASS_HA_C} = '160' or {CLARITY_DEP.RPT_GRP_SIX} in[7,8])
else If {?Location} = "Y" then {HSP_ACCOUNT.ACCT_CLASS_HA_C} <> '160' or isnull({HSP_ACCOUNT.ACCT_CLASS_HA_C})=true
or {CLARITY_DEP.RPT_GRP_SIX} <> [7,8] or isnull({CLARITY_DEP.RPT_GRP_SIX})=true)

Solution

  • This is another way that I was able to do this for selection criteria that worked. I went and set default value of 1/1/1900 in my paramters for dates. Then:

    (
    if {?Start Date} = date(1900,1,1) then
    {HSP.POST_DATE} = {HSP.POST_DATE}
    else
    {HSP.POST_DATE} in {?Start Date}
    )
    AND
    (
    if {?Admit Date} = date(1900,01,01) then
    {HSP.DATE_TIME} = {HSP.DATE_TIME}
    else
    {HSP.DATE_TIME} > {?Admit Date} 
    )
    AND
    (If {?Location} = "X" then ({HSP.ACCT_CLASS} ='160' or {DEP.RPT_GRP_SIX} in[7,8])
    else If {?Location} = "Y"
    then {HSP.ACCT_CLASS} <> '160' or isnull({HSP.ACCT_CLASS})=true
    or {DEP.RPT_GRP_SIX} <> [7,8] or isnull({DEP.RPT_GRP_SIX})=true)