【问题标题】:How to convert If statement from crystal report code to SQL case statements如何将水晶报表代码中的If语句转换为SQL case语句
【发布时间】:2020-02-26 08:23:27
【问题描述】:

我有一个用 Crystal 报表编写的 If 语句,我想将其转换为 SQL 代码。第一个代码块是水晶报表代码;最后一个代码块是 SQL 代码。谢谢!!

If {Command.TRT} = '23' then
    ( if {Command.CAT} = '200' or  {Command.CAT} = '300' then 'Home'
       else {Command.CAT} ='111' or {Command.CAT} = '22A' then 'School'
else "Other: " & {Command.CAT} )

else

if {Command.TRT} = '20' then (

if {Command.CAT} = '220' or  {Command.CAT} = '400 then 'Homework'

else "Other: " & {Command.CAT} )
)




Case When TRT  = '23' and CAT = '200' or CAT = '300' then 'Home'
     when TRT  = '23' and CAT = '111' or CAT = '22A' then 'School'

else

Case When TRT  = '20' and AT = '220' or CAT = '400 ' then 'Homework'

else Concat('Other: ',CAT)

【问题讨论】:

    标签: sql crystal-reports case


    【解决方案1】:

    在此处查看嵌套 CASE 示例:Best way to do nested case statement logic in SQL Server

    但从长远来看,创建和加入查找表可能会提供更简单、更不容易出错且更易于维护的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-28
      • 2020-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      相关资源
      最近更新 更多