Results 1 to 7 of 7
  1. #1
    SuperDude_123 is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    11

    I'm thinking I might need to use a SQL Prepared Statements


    As a continuation to my last post, I'm finding that when I use the LIKE '*' command, I don't always get consistent results. From looking in to it, I have a feeling that it's where I am concatenating my results for WHERE, and one thought was that I might need to use some prepared statement ahead of time, and feed it in to my WHERE later. Looking online, I haven't had much luck with this, so I was wondering if there was a way to solve my problem, or if there's a way to modify my WHERE line to get me consistent results.

    Code:
    SELECT Database.Description, Database.[Part Number], Database.Manufacturer, Database.Symbol, Database.[Job Number], Database.File, Database.DirectoryFROM [Database] INNER JOIN (SELECT Database.[Job Number] FROM [Database] GROUP BY Database.[Job Number] HAVING (((Sum([Symbol]=[Enter First Symbol] Or [Symbol]=[Enter Second Symbol]))=-2)))  AS qry1 ON Database.[Job Number] = qry1.[Job Number]
    WHERE (((Database.Symbol) LIKE '*' + [Enter First Symbol] + '*')) OR (((Database.Symbol) LIKE '*' + [Enter Second Symbol] + '*'))
    ORDER BY Database.File;

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    First, use & instead of + for string concatenation.

    Second, show example data.
    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
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Maybe show results too - especially incorrect ones. I could be way off here, but this is how I solve this part of your expression, assuming the inputs are 3 and -5 respectively. Shouldn't matter what they are, I see the result of the equals operation (=) being either True or False in any case.

    HAVING (((Sum([Symbol]=[Enter First Symbol] Or [Symbol]=[Enter Second Symbol]))=-2)))

    HAVING (((Sum([Symbol]= 3 Or [Symbol]=-5))=-2)))

    HAVING (((Sum(True Or False))=-2)))

    HAVING Sum(-1 Or 0))=-2 *this seems unlikely, not to mention I don't think I'd use Sum with OR
    Maybe I'm taking the whole thing out of context. Will have to revisit the posted link. Very nice idea to include that in your post SD.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    SuperDude_123 is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    11
    So here's some example data and how things are generally structured:

    Description Part Number Manufacturer Symbol Order Number File
    Directory
    Temp Sensor H1234 Honeywell TS1 11001 order_details.xls C:\orders\hill_billy_Bob_inc
    Speed Drive VFD112 Siemens VFD1 11001 order_details.xls C:\orders\hill_billy_Bob_inc
    120V Relay S1234 Siemens RE1 11001 order_details.xls C:\orders\hill_billy_Bob_inc
    Temp Sensor H1234 Honeywell TS1 11002 New_Order.xls C:\orders\Michael_Jackson_inc
    Temp Sensor H3344 Honeywell TS2 11002 New_Order.xls C:\orders\Michael_Jackson_inc
    Speed Drive VFD112 Siemens VFD 11002 New_Order.xls C:\orders\Michael_Jackson_inc
    120V Relay S1234 Siemens RE 11002 New_Order.xls C:\orders\Michael_Jackson_inc

    The type of errors that my code throws is that if I search on the symbols "VFD" and "TS1", I should get the following results:

    Temp Sensor H1234 Honeywell TS1 11001 order_details.xls C:\orders\hill_billy_Bob_inc
    Speed Drive VFD112 Siemens VFD1 11001 order_details.xls C:\orders\hill_billy_Bob_inc
    Temp Sensor H1234 Honeywell TS1 11002 New_Order.xls C:\orders\Michael_Jackson_inc
    Speed Drive VFD112 Siemens VFD 11002 New_Order.xls C:\orders\Michael_Jackson_inc


    But I will get something like this:

    Temp Sensor H1234 Honeywell TS1 11001 order_details.xls C:\orders\hill_billy_Bob_inc
    Speed Drive VFD112 Siemens VFD1 11001 order_details.xls C:\orders\hill_billy_Bob_inc
    Temp Sensor H1234 Honeywell TS1 11002 New_Order.xls C:\orders\Michael_Jackson_inc


    I haven't ran all possible situations yet, but this is the type of error pattern that I am getting, where it will puke on some exact matches, but works on other exact matches.

    I did try modifying the code from "+" to "&", and it didn't do anything different.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    If you searched for VFD1, you won't have got the record which has VFD
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    SuperDude_123 is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    11
    By using the LIKE '*', I've managed to get partial data, and that's what I am after. I'm not trying to get exact matches, but partial matches as well. So if I search for TS, I want to see all TS's (TS1, TS2, ....), and not just "TS".

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    So did you search for *VFD* or *VFD1*?
    If the latter, then as already stated you wouldn't get the VFD record which you said was missing in your output
    If the former, you should indeed have got both records

    I'm asking as you said you searched for TS1 rather than *TS*
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. .CSV file thinking it's .SLK Can't auto import
    By MTSPEER in forum Programming
    Replies: 6
    Last Post: 08-17-2017, 11:32 AM
  2. Replies: 0
    Last Post: 05-25-2015, 06:46 PM
  3. Help with thinking about tables and forms
    By bytreeide in forum Forms
    Replies: 2
    Last Post: 05-19-2015, 02:12 PM
  4. Prepared SQLQuery on my DB java
    By ReignMan in forum Access
    Replies: 1
    Last Post: 01-16-2015, 09:33 AM
  5. Inventory, but not as bad as you might be thinking.
    By theevilsam in forum Programming
    Replies: 3
    Last Post: 02-15-2012, 07:10 PM

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