6 Replies Latest reply on May 11, 2011 2:38 PM by LaRetta_1

# Case statement left numbers and a range

### Title

Case statement left numbers and a range

### Post

Here's what I have not sure where I am going wrong?

Left (number_contract ; 2) =  ≥ 13  and  ≤ 99; "Head Quarters";

• ###### 1. Re: Case statement left numbers and a range

Try:

GetAsNumber (Left (number_contract ; 2) ) ≥ 13  and  GetAsNumber (Left (number_contract ; 2) ) ≤ 99 ; ...

Which can be rewritten as:

Let ( Digits = GetAsNumber (Left (number_contract ; 2) ) ; Case ( Digits ≥ 13  and Digits  ≤ 99 ) ; ...

• ###### 2. Re: Case statement left numbers and a range

Question will that get rid of the issue that the case statement that I wrote keeps dropping the leading zero when saved?

Here is what I wrote but when I wrote it everything was = 01, = 02, ..... = 12

Case (Left ( number_contract ; 2) = 1; "District 1";
Left (number_contract ; 2) = 2; "District 02";
Left ( number_contract ; 2) = 3; "District 03";
Left ( number_contract ; 2) = 4; "District 04";
Left ( number_contract ; 2) = 5; "District 05";
Left ( number_contract ; 2) = 6; "District 06";
Left (number_contract ; 2) = 7; "District 07";
Left ( number_contract ; 2) = 8; "District 08";
Left ( number_contract ; 2) = 9; "District 09";
Left (number_contract ; 2) = 10; "District 10";
Left ( number_contract ; 2) = 11; "District 11";
Left ( number_contract ; 2) = 12; "District 12";
Left (number_contract ; 2) =  13; "Head Quarters";
)

• ###### 3. Re: Case statement left numbers and a range

If you are comparing a value to a number, you need to make sure the type produced by your expression is of type number.

When they are of type number, 01 = 1 is a true statement. When they are of type text, "01" = "1" is False.

• ###### 4. Re: Case statement left numbers and a range

Isn’t the field number_contract a number field which only holds the number 1, 2, 3 etc and you want to assign the text equivalent of district (with leading zero or as headquarters) in a new calculation?  Is this correct?  And you want to pad the number with leading zero if less than 2 places?

Try calculation, result is text with:

Case (
number_contract  ≥ 13 and number_contract ≤  99 ; "Head Quarters" ;
"District " & Right ( "00" & number_contract ; 2 )
)