on 09-17-2008 9:27 PM
I'm having difficulty locating documentation for the use of CASE statements in Crystal syntax. My database administrator does not allow me to write SQL expressions so I need to covert the SQL below to Crystal Syntax. Can anyone help me? Thank you very much!!
Select
CASE
WHEN projects.ProjType like 'S%' then 'Shopping Center'
WHEN projects.ProjType like 'I%' then 'Industrial'
WHEN projects.ProjType like 'O%' then 'Office Building'
ELSE 'Other'
END
from projects
Here is the syntax:
select {projects.ProjType}
case is like 'S%' : "'Shopping Center"
case is like 'I%' : "Industrial"
case is like 'O%' : "Office Building"
default : "Other"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Let's assume column XYZ has both numbers (1), and letters (any alphabet).
I have a case statement on SQL to turn any value that's not 1 into 0, then I am getting a sum of that column.
I am also grouping by Row A, B etc to get aggregated sum of column XYZ for those group.
Now on Crystal Reports function, I need to sum up values under column XYZ for all the groups.
If I try using sum function like below, I get an error stating:
"A number field or currency amount field is required here"
(sum({Command.XYZ}))
So I thought if I can use a case statement to change the non-numbers to 0 prior to sum that will probably resolve it. But I could not get the below case statement to work either (Error: A string is required).
SELECT {Command.XYZ}
Case 1:
1
Default:
0;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Whether if I use CASE or SWITCH, I get a similar error
With SWITCH, "A string is required here" highlighting the one underlined below
Switch(
{Command.XYZ} = 1, 1,
true, 0
)
If I use CASE, I get an error "A number, currency amount, boolean, date, time, date-time, or string is expected here" and this one is highlighted on the equal sign.
SELECT {Command.XYZ}
Case = 1:
1
Default:
0;
Hi David,
I have to look that one up all the time. It's pretty easy to find in the formulas help, but they call them 'SELECT' statements, instead of CASE statements.
As I recall the syntax is:
SELECT {field}
Case <value>:
action
Case <another value>:
another action
Default:
action;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.