Results 1 to 2 of 2
  1. #1
    jacjacjac is offline Novice
    Windows XP Access 2000
    Join Date
    Dec 2012
    Posts
    7

    Access SQL ORDER BY putting NULL values last in query

    Hello,

    NOTE: Im working in MS Access 2003, only results in this SQL/database (not mysyl, MSSQL etc)

    I want to be able to ORDER an SQL query and put the NULL values last.

    I have a basic databse:
    Table name: PeopleTable
    Field names: TableID, PersonField, PersonID



    The aim is to order by PersonID and put the NULL values last

    See pic1.jpg;
    Click image for larger version. 

Name:	pic1.JPG 
Views:	1 
Size:	15.3 KB 
ID:	10419
    The picture (pic1.jpg) shows the database as it is without a query.


    See pic2.jpg;
    Click image for larger version. 

Name:	pic2.JPG 
Views:	1 
Size:	16.4 KB 
ID:	10418
    Picture 2 (pic2.jpg) shows the query results when I use the orderby statement (SELECT * FROM PeopleTable ORDER BY PersonID
    As you can see it shows the results ordered by the PersonID however the NULL values are first.

    See pic3.jpg
    Click image for larger version. 

Name:	pic3.JPG 
Views:	1 
Size:	14.7 KB 
ID:	10420
    Desired results, it is ordered by the PeronID and the NULL values are last (NOTE this is an editied screenshot).
    How can i achieve this is MS Access 2003?

    Thanks,

    Jac

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Need to handle the Null by converting it to another value that will always sort after the other data. Create another field with expression and use that field to do the sorting, like:

    SortID: Nz(PersonID,999999)

    or

    SortID: Nz(PersonID,"z")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Sort order with null values
    By Alsail77 in forum Access
    Replies: 23
    Last Post: 08-27-2012, 05:04 PM
  2. Query and Null Values
    By ydrasil281 in forum Queries
    Replies: 1
    Last Post: 08-06-2012, 03:32 PM
  3. Query with null values
    By Psyclone in forum Queries
    Replies: 3
    Last Post: 03-30-2011, 09:57 PM
  4. Null Values in query
    By LesleaOH in forum Queries
    Replies: 0
    Last Post: 10-19-2009, 04:45 PM
  5. Null Values not showing up in a Query
    By Valli in forum Queries
    Replies: 0
    Last Post: 01-04-2006, 03:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums