将Crystal IF语句转换为SQL

时间:2019-05-29 15:33:34

标签: sql tsql crystal-reports crystal-reports-xi

我正在将Crystal Report转换为SQL查询。公式包含在Crystal Report中。

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

这是水晶配方

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
          )

1 个答案:

答案 0 :(得分:2)

是的,很好。 如果公式设置为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
          )
)