473,387 Members | 1,435 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Sorting Integers in a Query (Using Nz)

Hi there,

I have an IIF expression that is returning a 0 (exact match), 1
(partial match), or 2 (no match) based on comparing text fields (see
below).

However, when I try to sort the results (either using an ORDER BY _or_
using the A-Z toolbar button on the datasheet), it doesn't work. It
sorts the 0s to the top, but the 1s and 2s are mixed up - the records
where one of the text fields is NULL show as 2s, but sort as 1s!

(If I wrap the entire expression in CInt(), it behaves the same way.)

If I remove the Nz() from around my text strings, the sorting works as
you'd expect (0s then 1s then 2s). But then the answers I get aren't
correct for matching purposes - e.g. Smith vs NULL comes up as a
"partial match", but for my purposes (i.e. being conservative) I want
it as a "no match".

Expression:
Surname_Match:
IIf(Person.Surname=New_Person.Surname,0,IIf(Person .Surname Like "*" &
Nz(New_Person.Surname,"0000") & "*" Or New_Person.Surname Like "*" &
Nz(Person.Surname,"0000") & "*",1,2))

Any idea how I can get this sort working without having to remove the
Nz()?

Thanks,
- LoopyNZ -

Dec 27 '06 #1
1 1753
I've worked around the problem. I still don't completely understand why
the sorting would be so strange, but I've shifted the Nz() to outside
the core expression and also taken empty strings into account, and the
sorting now works.

New Expression:
Surname_Match: IIf(Nz([Person].[Surname],"")="" Or
Nz([New_Person].[Surname],"")="",2,IIf([Person].[Surname]=[New_Person].[Surname],0,IIf([Person].[Surname]
Like "*" & [New_Person].[Surname] & "*" Or [New_Person].[Surname] Like
"*" & [Person].[Surname] & "*",1,2)))
- LoopyNZ -

LoopyNZ wrote:
Hi there,

I have an IIF expression that is returning a 0 (exact match), 1
(partial match), or 2 (no match) based on comparing text fields (see
below).

However, when I try to sort the results (either using an ORDER BY _or_
using the A-Z toolbar button on the datasheet), it doesn't work. It
sorts the 0s to the top, but the 1s and 2s are mixed up - the records
where one of the text fields is NULL show as 2s, but sort as 1s!

(If I wrap the entire expression in CInt(), it behaves the same way.)

If I remove the Nz() from around my text strings, the sorting works as
you'd expect (0s then 1s then 2s). But then the answers I get aren't
correct for matching purposes - e.g. Smith vs NULL comes up as a
"partial match", but for my purposes (i.e. being conservative) I want
it as a "no match".

Expression:
Surname_Match:
IIf(Person.Surname=New_Person.Surname,0,IIf(Person .Surname Like "*" &
Nz(New_Person.Surname,"0000") & "*" Or New_Person.Surname Like "*" &
Nz(Person.Surname,"0000") & "*",1,2))

Any idea how I can get this sort working without having to remove the
Nz()?

Thanks,
- LoopyNZ -
Dec 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
18
by: Scott | last post by:
I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are...
16
by: aruna | last post by:
Given a set of integers, how to write a program in C to sort these set of integers using C, given the following conditions a. Do not use arrays b. Do not use any comparison function like if/then...
6
by: Michel | last post by:
Hi All, I need to loop through a sorted datatable. Looping is not a problem, but sorting is. The datacolumns on which I want to sort, exists of numbers, which causes the 10 to appear before...
16
by: Kittyhawk | last post by:
I would like to sort an Arraylist of objects on multiple properties. For instance, I have a Sort Index property and an ID property (both integers). So, the results of my sort would look like this:...
7
by: abracadabra | last post by:
I am reading an old book - Programming Pearls 2nd edition recently. It says, "Even though the general C++ program uses 50 times the memory and CPU time of the specialized C program, it requires...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
4
by: slapsh0t11 | last post by:
Hello! I need help with a program that I believe I am nearly done with. However, there seems to be a few details that preclude me from success. Here is my assignment: Here is my class file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.