Results 1 to 10 of 10
  1. #1
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91

    query where one field has a product should be order Desc compared to second field

    Hi all,



    I need to adjust a query. In this query I get the oldest cases from a table and they are ordered the hightes days on top. Now I need to add the possibility that if one field [Products] contains a product, they should be on top and those with no products at the bottom.

    Greetings.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    add an extra field (NOT CRITERIA): not IsNull([Products]) as HasProduct

    sort on HasProduct, true sorts to the top

  3. #3
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    HI,

    It gives me error with: as HasProduct

    I inserted like this: Expr5: not IsNull([Products])

    Where do I fit the HasProduct?

    Greetings.

  4. #4
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    Right after, NOT IsNull([Products]) As HasProduct


    Then refer to that expr as HasProduct for the rest of you query.

    Then as ranman said sort on HasProduct.

  5. #5
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi, still gives me error (on: As)
    Expr5: not IsNull([Products]) as HasProduct

    Maybe I'm just putting it in the wrong spot, but I put it in a empty field of the query.

    "The expression you entered contains invalid syntax
    you may have entererd an operand without an operator"

    Greetings.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    Not IsNull([Products]) As HasProduct is what you will see in the query SQL View

    In Design View grid do this:

    HasProduct: Not IsNull([Products])
    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.

  7. #7
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi June7,

    Big thanks :-)
    I have basic knowledge of SQL and I'm using the design view to create the queries and that is why I did not get it :-(

    When I thought it was finished, they came again with a new criteria :-(
    If the fiield Produts has a product called "New Product", it should be apearing at the end, but before where the product field is empty (the ones with empty products field still need to be in the list but at the very end).

    Greetings.

  8. #8
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi all,

    Almost there :-)
    I managed with the "New Product". I made the IFF that if the field has a New Product it should give the value False (shows up as 0) and then I could filter on it with order in ascending.
    I still need to manage how to deal with the IsNull. So if the field [New Product] is null, it should give maybe also False.

    Greetings.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    Maybe:

    IIf([Products] Is Null, 0, IIf([Products]="New Product", 1, 2))

    http://allenbrowne.com/QueryPerfIssue.html
    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.

  10. #10
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi June7,

    That did the trick :-)

    Thanks a lot.

    Greetings.

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

Similar Threads

  1. Replies: 3
    Last Post: 01-18-2015, 06:05 PM
  2. Replies: 5
    Last Post: 09-08-2014, 02:23 PM
  3. Replies: 7
    Last Post: 08-28-2014, 01:33 PM
  4. ASC or DESC Sort Based On Another Field
    By KikoMatsing in forum Access
    Replies: 1
    Last Post: 08-12-2014, 10:34 AM
  5. ORDER BY error when using DESC in an IIf
    By Smitoris in forum Queries
    Replies: 2
    Last Post: 10-30-2011, 02:48 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