Thursday, March 16, 2006

I recently run into the problem of not getting the right order for records on a temporary table. This is how data looked when using and index created as follows:

INDEX ON UPPER(company_name)+UPPER(dept_name)+UPPER(EMPLOYEE_LASTNAME)+UPPER(EMPLOYEE_FIRSTNAME) TAG ciadeptemp

COMPANY_NAME,DEPT_NAME,LAST_NAME,FIRST_NAME
Company 1, null,j,c
Company 2, Sales,f,c
Company 1,Tech Support,g,c

What happened? Shouldn't I get all the 'Company 1' records before seeing 'Company 2'? Of course, but that is in case there were not null values in any of the fields that are part of the index key.

In my case, field "dept_name" accepted .null. values so the index key for that record evaluates to .NULL., therefore, appears at the top. This new index key solved it:

INDEX ON UPPER(company_name)+UPPER(IIF(ISNULL(dept_name),space(40),dept_name))+UPPER(EMPLOYEE_LASTNAME)+UPPER(EMPLOYEE_FIRSTNAME) TAG ciadeptemp

Never run into this before, so many years working with VFP but how much I've got to learn yet. Did anybody resolve this in a different way?

5/16/2006 5:07:45 PM (Eastern Daylight Time, UTC-04:00)
I don't see the difference between the two tags. I'm guessing the first one shouldn't take null into account.

Also, don't forget about NVL(). You could rewrite as
INDEX ON UPPER(company_name + NVL(dept_name,space(40)) + EMPLOYEE_LASTNAME + EMPLOYEE_FIRSTNAME) TAG ciadeptemp
5/16/2006 7:23:37 PM (Eastern Daylight Time, UTC-04:00)
Hello Eric,

Oops, my mistake!!! first index key should read INDEX ON UPPER(company_name)+UPPER(dept_name)+UPPER(EMPLOYEE_LASTNAME)+UPPER(EMPLOYEE_FIRSTNAME) TAG ciadeptemp . I've already corrected the original post, Thank you!!!

Yes you could use NVL(), however, assuming that this is the only tag for the table, the size of the CDX file generated is the same for both cases (NVL or ISNULL), plus NVL seems to be slightly slower (not significantly though).
Juan Calcagno
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):