0

I have an If statement written in Crystal report that I wanted to convert to SQL code. The first code block is the Crystal report code; the last code block is the SQL code. Thank You!!

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)
entreprenerds
  • 856
  • 10
  • 20

1 Answers1

0

See nested CASE example here: Best way to do nested case statement logic in SQL Server

But long-term, creating and joining to lookup tables may provide a simpler, less error-prone, and more maintainable solution.

MilletSoftware
  • 1,913
  • 2
  • 10
  • 12