sqlt-sqlcrystal-reportscrystal-reports-xi

Converting Crystal IF statements to SQL


I am converting a Crystal Report to a SQL query. Embedding in the Crystal Report are formulas.

I am trying to convert the Crystal IF statements to a SQL WHERE clause

This is the Crystal formula

if {loanview.LOAN_STATUS} in 
["COMMITMENT","APPLICATION","PA_APPROVED","PRE_CLOSING","FUND_HOLD","GRANTSOURCE"] then "SHOW" else

if {loanview.LOAN_STATUS} in ["CURRENT","LATE+30","LATE+60","DELINQ+90","CLOSED"] 
and {BILLINFO.REVOLVING_CR} = "" and {balview.GBOOK_VALUE_P} = 0 then "HIDE" else

if {loanview.LOAN_STATUS} in ["CURRENT","LATE+30","LATE+60","DELINQ+90","CLOSED"] 
and {BILLINFO.REVOLVING_CR} = "" and {balview.GBOOK_VALUE_P} <> 0 then "SHOW" else

It looks like I need a WHERE clause. My thought is the WHERE = the Crystal SHOW and then just omitting the Crystal HIDE part. Does this make sense?

WHERE
      (
          loanview.LOAN_STATUS IN ( 'COMMITMENT', 'APPLICATION', 'PA_APPROVED', 'PRE_CLOSING', 'FUND_HOLD',
                                    'GRANTSOURCE'
                                  )
          OR
          (
              loanview.LOAN_STATUS IN ( 'CURRENT', 'LATE+30', 'LATE+60', 'DELINQ+90', 'CLOSED' )
              AND BILLINFO.REVOLVING_CR = ''
              AND balview.GBOOK_VALUE_P <> 0
          )

Solution

  • Yes, it's fine. Only point of failure could be if the formula is set to default values for null. That means that a null BILLINFO.REVOLVING_CR is automatically converted to empty string. So a better way to write it just to be sure is:

    WHERE
          (
              loanview.LOAN_STATUS IN ( 'COMMITMENT', 'APPLICATION', 'PA_APPROVED', 'PRE_CLOSING', 'FUND_HOLD',
                                        'GRANTSOURCE'
                                      )
              OR
              (
                  loanview.LOAN_STATUS IN ( 'CURRENT', 'LATE+30', 'LATE+60', 'DELINQ+90', 'CLOSED' )
                  AND (BILLINFO.REVOLVING_CR = '' or BILLINFO.REVOLVING_CR IS NULL)
                  AND balview.GBOOK_VALUE_P <> 0
              )
    )