> >
> >
SELECT CPY.company_name, CTC.firstname, CTC.lastname ;
> > FROM company CPY ;
> > LEFT OUTER JOIN contacts CTC ON CTC.companyfk = CPY.companypk ;
> > WHERE CPY.company_name LIKE "A%" ;
> > INTO CURSOR cur_list
> >
> > SELECT cur_list
> > SCAN
> > lcName = ALLTRIM( lastname ) + IIF( NOT EMPTY( firstname ), ", " + ALLTRIM( firstname ), "" )
> > *** More code here
> > ENDSCAN
> >
> > The catch above? No test for NULLS! Note the OUTER JOIN in the query. Concatenating the names like this results in NULL if either the First, or Last name is NULL. It is an anomaly (if not actually a bug) that ALLTRIM( NULL ) returns NULL and not an error even though attempting to ALLTRIM() any other invalid data does throw an error.
> >
> > Regards
> > Andy Kramek
> > Microsoft MVP (Visual FoxPro)
> >
Tightline Computers Inc, Akron Ohio, USA>
> If there's no contact for the company both name columns will be Null. You couldn't get a case where just the firstname is null, but lastname isn't, could you? I assume the default for the column s must be '', and NOT NULL.
>
> -Anders
Actually this was real code, from a real application and a real scenario. Plenty of contacts are entered as only first names either because the last name is never given or is specifically denied (try and find the last name of your IRS contact - if you can get anything other than "Agent 123" to begin with).
There are two issues here.
[1] Bad data design - as you say the default should have been set to an empty string instead of allowing NULL
[2] An anomaly (not to say 'bug') in FoxPro's handling of ALLTRIM() where concatenating a NULL does NOT throw an error
However, in spite of these issues, the code itself is bad because of the implicit assumptions it makes and the failure to check for even the possibility of an error - which was my point!
Regards
Andy Kramek
Microsoft MVP (Visual FoxPro)
Tightline Computers Inc, Akron Ohio, USA