Case statement

Mark123

New Member
Hi,

I am trying to convert all "yes" to 1 and all "no" to 0 in a case statement.

Here is my code:

for each prospect where:
display
prosp_id
name
address
active
case active:
when "yes" then 1.
when "no" then 0.
end case.
skip.
end

However I receive a message "Line2. Colon followed by white space terminates a statement. (199)"

If I comment Case block I don't receive any errors. By my Case starts with line 7 , not 2.

Thanks.
 

Mark123

New Member
I ran your code, burt received another error
"Incompatible data types in expession or assignment. (223)
Could not understand line 3. (196)"

If I comment the line with (if active ... the code runs fine.
 

zee

New Member
Looks like your field is logical, rather than character. If so, remove the quotes around it. (if active = yes then 1 else 0)
 
Ok, I've reread it - I was somewhat confused by a couple of instances of illogical and unformatted syntax.

Mark123, your first error is happening because you are putting a code block

Code:
case active:
when "yes" then 1.
when "no" then 0.
end case.

where an expression (ie. a variable or literal) is expected.

Your second error is probably happening because as zee suggested 'active' is a logical field, so you refer to it like so:

if active = yes...

So remove the quotes from leite1969s response.

Code:
display
   prosp_id
   name 
   address 
   active
   (if active = yes then 1 else 0)
skip.
 

schaapie

Member
How about:

Code:
display prospect.active format "1/0".

and wouldn't/shouldn't "if active = yes" just be "if active"?
 
Top