Print Page | Close Window

Convert IF THEN ELSE to CASE statement

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22624
Printed Date: 04 May 2024 at 1:42pm


Topic: Convert IF THEN ELSE to CASE statement
Posted By: Hegdej
Subject: Convert IF THEN ELSE to CASE statement
Date Posted: 11 Jun 2018 at 10:19am
I have the below if then else statement and need help converting to a CASE statement.

if(isnull({@cond1})=false) then 'Cond1'
else if(isnull({@cond2})=false) then 'Cond2'
else if({Command.Age}<3) then 'Under 3'
else if({Command.Age}>17) then 'Above 18'
else 'Between 3 to 17'

This categorizes each element only to one column and that is incorrect. Need the element to be counted in multiple columns. Eg. in 'Cond1' column and one of the age columns or 'Cond1' and 'Cond2' and one of the age columns.

Thanks in advance!



Replies:
Posted By: kevlray
Date Posted: 12 Jun 2018 at 4:11am
I am assuming that you are using MS-SQL.

case when {@cond1} is not null then 'Cond1'
        when {@cond2} is not null then 'Cond2'
        when {Command.Age} < 3 then 'Under 3'
        when {Command.Age} > 17 then 'Above 18'
        else 'Between 3 to 17' end


Posted By: Hegdej
Date Posted: 12 Jun 2018 at 4:36pm
Thank you!



Print Page | Close Window