将 Crystal IF 语句转换为 SQL

Converting Crystal IF statements to SQL

我正在将 Crystal 报告转换为 SQL 查询。 Crystal 报表中嵌入了公式。

我正在尝试将 Crystal IF 语句转换为 SQL WHERE 子句

这是Crystal公式

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

看来我需要一个 WHERE 子句。我的想法是 WHERE = Crystal SHOW 然后省略 Crystal HIDE 部分。这有意义吗?

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
          )

是的,很好。 唯一的失败点可能是将公式设置为 null 的默认值。这意味着 null BILLINFO.REVOLVING_CR 会自动转换为空字符串。 所以为了确定,更好的写法是:

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
          )
)