cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Case statement in crystal

Former Member
0 Likes
7,688

Case when(c.name between 1 and 3) then 1

         when (c.name between 4 and 6) then 1

         when(c.name between 7 and 9) then 1

         else 0

end as xyz

how to write this as a formula in crystal?

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Likes

Hi Thanks but I realised there is some thing else

I have column which shows the data EXACTLY like this

1- Low utility

2-Low utility

3- Low utility

4- Marginal

5- Marginal

6- Marginal

7- Indicated

8- Indicated

9- Indicated

10 Acceptable

I want to group them between 1 to 3 and 4 to 6 and 7 to 9 and 10.

I am thinking of case statement. 

DellSC
Active Contributor
0 Likes

So instead of working with {c.name}, work with ToNumber(Left({c.name}, 1)).

-Dell

DellSC
Active Contributor
0 Likes

There is a case statement in Crystal, but in versions before that was available, I learned to use a Switch statement.  For your example, it would look something like this:


Switch(

  c.name in 1 to 3, 1,

  c.name in 4 to 6, 2,

  c.name in 7 to 9, 3,

  true, 0

)

The first part of each pair is the condition to test for and it must evaluate to true or false, the second is the value you would like to return.  The "true" at the end specifies the default value.

-Dell

abhilash_kumar
Active Contributor
0 Likes

HI Chandu,

Try:

Select {c.name}

Case 1 to 3: 1

Case 4 to 6: 1

Case 7 to 9: 1

Default: 0

This particular example can also be written as:

If {c.name} in [1 to 9] then 1

or,

Select {c.name}

Case 1 to 9 : 1

default: 0

-Abhilash