Order By Problem (1 Viewer)

Meltdown

Registered User.
Local time
Today, 22:55
Joined
Feb 25, 2002
Messages
472
In a query I'm trying to return a list of rows sorted by ServiceType Ascending and then the last item in the list should be a row called "Add Edit Value" (see screenshot).

If I 'ORDER BY 2' then the "Add/Edit" row appears at the top which is not what i want.

My SQL:
SELECT '' As ServiceTypeID, 'ADD/EDIT VALUES' As ServiceType FROM ServiceTypes UNION SELECT ServiceTypes.ServiceTypeID, ServiceTypes.ServiceType FROM ServiceTypes
ORDER BY 1 DESC;

Appreciate any help.

Regards
Melt
 

Attachments

  • screen1.jpg
    screen1.jpg
    9.4 KB · Views: 117
Last edited:

pr2-eugin

Super Moderator
Local time
Today, 22:55
Joined
Nov 30, 2011
Messages
8,494
Well the ORDER BY does what you ask it to do, but not what you want to do. You might need a sprinkle of VBA to get this going !
 

JHB

Have been here a while
Local time
Today, 23:55
Joined
Jun 17, 2012
Messages
7,732
If you can "live" with a space in front of ' ADD/EDIT VALUES' then:

Code:
SELECT '' As ServiceTypeID, ' ADD/EDIT VALUES' As ServiceType FROM ServiceTypes 
UNION SELECT ServiceTypes.ServiceTypeID, ServiceTypes.ServiceType FROM ServiceTypes
ORDER BY ServiceType DESC
 

Meltdown

Registered User.
Local time
Today, 22:55
Joined
Feb 25, 2002
Messages
472
Thanks for the replies.

JHB, that won't work as I need the ServiceType Ascending, which will still leave the Add/Edit value at the top of the list.

Regards
Melt
 

JHB

Have been here a while
Local time
Today, 23:55
Joined
Jun 17, 2012
Messages
7,732
Yes sorry, I forgot the Ascending part, so you need as pr2-eugin wrote some VBA code, I've made an example for you in the attached database.
 

Attachments

  • Sort.mdb
    268 KB · Views: 44
  • Sorted.jpg
    Sorted.jpg
    26.8 KB · Views: 110

Meltdown

Registered User.
Local time
Today, 22:55
Joined
Feb 25, 2002
Messages
472
Thanks a lot JHB -- nice piece of work!

Regards
Melt
 

Users who are viewing this thread

Top Bottom