Moving blank values to the end of sorted results

Post Reply
foosh101
Posts: 61
Joined: Tue Oct 22, 2002 2:13 pm

Moving blank values to the end of sorted results

Post by foosh101 »

In my search results, I give the user the ability to sort by a number of different fields. However, some of them don't always have values in them. When I do an 'ORDER BY Field', all records that do not have a value in them come up first. Is there any good way to make the blank values always show up at the end of the results, whether I sort descendingly or ascendingly. If the user wants to sort by that field, having several pages of records that have no value in that field are not really of any use to them. -Thanks
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Moving blank values to the end of sorted results

Post by John »

Not really (they will be at the end descending, as an empty string always compares less than any other string). If they are of no interest you could try removing them from the results altogether.
John Turnbull
Thunderstone Software
foosh101
Posts: 61
Joined: Tue Oct 22, 2002 2:13 pm

Moving blank values to the end of sorted results

Post by foosh101 »

yeah, thats what I figured. Unfortunately I can't remeove those results because while that field being blank would cause the need to have it show up at the end of the search results, it still need so show up in the results somewhere because it meets the users search criteria. I was just wondering if anyone else had a similar problem and/or texis had a neat way to solve for this issue.
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Moving blank values to the end of sorted results

Post by mark »

Maybe somewhat expensive, but for ascending sort you might sandr() the field changing empty to zzz or whatever it takes to be last. Then clear that special value before displaying it.
foosh101
Posts: 61
Joined: Tue Oct 22, 2002 2:13 pm

Moving blank values to the end of sorted results

Post by foosh101 »

Actually, that is a pretty good idea. I can do one better however, and do the replacement of the blank values before it even gets into texis so their is no need to do the sandr and reduce performance. Thanks for the help guys.
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Moving blank values to the end of sorted results

Post by mark »

If you set the value in the table the problem will be right back, but for descending sort instead of ascending.
foosh101
Posts: 61
Joined: Tue Oct 22, 2002 2:13 pm

Moving blank values to the end of sorted results

Post by foosh101 »

Yeah, I know. I realized the same thing about 5 minutes after I posted that. Thanks for the help.
Post Reply