Results 1 to 6 of 6
  1. #1
    KWarzala is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Sep 2009
    Posts
    35

    Sort Date in SQL UNION statement

    Hello,



    I have a combo box with the following Row Source:
    Code:
    SELECT DISTINCTROW tblReturnMerchandise.ReturnDate
    FROM tblReturnMerchandise
    UNION
    SELECT "" FROM tblReturnMerchandise;
    This shows the dates from tblReturnMerchandise (Unique Values only) with a blank field so the person can select none of the dates.

    Ideally i would like the blank to be at the top, with the dates descending, but i would settle for the dates ascending. I can't get an ORDER BY statement to work on this query.

    Thank you!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I don't really understand that SQL, but try

    SELECT DISTINCTROW tblReturnMerchandise.ReturnDate, 1 As SortField
    FROM tblReturnMerchandise
    UNION
    SELECT "", 0 As SortField FROM tblReturnMerchandise
    ORDER BY SortField, ReturnDate DESC
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    KWarzala is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Sep 2009
    Posts
    35
    You're the best! thank you so much!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    I would use Null instead of "" if this control is bound to a date/time field.
    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.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    KWarzala is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Sep 2009
    Posts
    35
    Quote Originally Posted by June7 View Post
    I would use Null instead of "" if this control is bound to a date/time field.
    It's not actually bound to anything i'm just using it to filter a form, but thanks for the suggestion

    thanks!

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

Similar Threads

  1. Sort records by date added
    By gmaster in forum Programming
    Replies: 8
    Last Post: 06-12-2014, 01:21 AM
  2. Replies: 10
    Last Post: 05-09-2014, 10:54 AM
  3. Make report sort by IDs and then by Date
    By taimysho0 in forum Programming
    Replies: 4
    Last Post: 07-03-2012, 01:03 PM
  4. Date function within a Union Query
    By pmplyons in forum Programming
    Replies: 2
    Last Post: 08-24-2011, 11:33 AM
  5. Sort by date and year
    By Douglasrac in forum Queries
    Replies: 13
    Last Post: 04-07-2011, 10:02 AM

Tags for this Thread

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