如何将If语句从Crystal报表代码转换为SQL Case语句

时间:2019-10-31 00:40:45

标签: sql crystal-reports case

我有一个用Crystal报表编写的If语句,我想将其转换为SQL代码。第一个代码块是Crystal报表代码。最后一个代码块是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)

1 个答案:

答案 0 :(得分:0)

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

但是从长期来看,创建并联接到查询表可能会提供一种更简单,更不易出错且更易于维护的解决方案。