Results 1 to 3 of 3
  1. #1
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206

    SQL variable to Sort


    I have this SQL variable statement and it works to sort in descending order. strSort = "tblParts.[P_Quantity]" & "Desc" ( "ORDER BY " & strSort & ";").
    I would like to add a 2nd Sort criteria to my strSort statement,
    "tblParts.[P_Name], but can't seem to get the correct format.
    "tblParts.[P_Quantity], tblParts.[P_Name]" works but I would like the descending order.

    Thanks,
    Tom

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    You need a separator space in front of DESC.

    Why bother with concatenation?

    strSort = "P_Name, P_Quantity DESC"


    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.

  3. #3
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206
    That works but doesn't sort on Quantity first! Sorts on Name then Quantity. So if I use "tblParts.P_Quantity DESC, tblParts.P_Name" this will work the way I need it. Quantity then Name. I knew it was something easy! This is my goto after many searches on google.
    Thanks!
    Tom

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

Similar Threads

  1. Replies: 2
    Last Post: 07-23-2019, 01:37 PM
  2. Replies: 1
    Last Post: 04-07-2014, 02:59 AM
  3. Declaring a Variable Constant (Sort Of)
    By emmahope206 in forum Programming
    Replies: 1
    Last Post: 02-27-2013, 11:15 AM
  4. sort filter, doesn't sort everything
    By deso in forum Queries
    Replies: 4
    Last Post: 01-25-2013, 05:27 AM
  5. Replies: 0
    Last Post: 08-10-2011, 11:59 AM

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