Question : IIF Field Length Question

OK, I can't figure this out!
I have an IIF Statement (see below):

SELECT
     IIF(ALLTRIM(Stub_tot.doc_id)="2","SoftPak","Tower") AS SystemType;
FROM Table

However when I view the data in the CURSOR in the Data Session Window I only see:
"SoftP" or "Tower"

It appears it is taking the length of the word Tower and gives the field that length so because SoftPak is longer than Tower it truncates the "ak" of the name.

So my question is how do I fix this?

Thanks,
Mark

Answer : IIF Field Length Question

Field length is not determined by IIF, but the first record of the result, if the first record results in "SoftPak" the SystemType field would be C(7), if the first record is a "Tower" the SystemType is C(5). That's the way foxpro determines field types of an expression/ a computed field.

So cast to the field type and legth you want:
CAST( IIF(...) As C(7)) As SystemType ...

or PAD:
PADR(IIF(...,"SoftPak","Tower"),7) AS SystemType ...

or simply add the needed two spaces to "Tower":
IIF(...,"SoftPak","Tower  ") AS SystemType

Bye, Olaf.
Random Solutions  
 
programming4us programming4us