Results 1 to 5 of 5

Thread: quote error in query

  1. #1

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360

    quote error in query

    Hello kids! Its time to play WHATS WRONG WITH THIS CODE!!!!

    Lets meet contestant number one. This sloppy programmer wants to have some values he gets from a form to be queried against his Access database. When inserting the variable values into his query using some sloppy code like


    strQuery = strQuery & "SELECT * HAVING price BETWEEN '" & fromPrice & "' AND '" & toPrice & "'"
    ...

    He gets errors!!!!

    For 500 points, can somebody tell me WHATS WRONG WITH THIS CODE!?!?!
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    wow 500 points

    Code:
    strQuery = strQuery & "SELECT * HAVING price BETWEEN '"  & _
    "fromPrice & "' AND '" & toPrice & "'"
    You haven't got a from clause in there !
    In a Select statement, you need to specify which table you need to get this from :
    Code:
    strQuery = strQuery & "SELECT * FROM Table1 HAVING price BETWEEN '" & _ 
    fromPrice & "' AND '" & toPrice & "'"
    Also, you might want to check in debug mode the values of fromPrice & toPrice to make sure they're entered right - maybe using cint(toPrice) to convert this to a number before passing it in ?
    Last edited by alex_read; Jun 28th, 2001 at 03:34 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    oooooh sorry but that is not the correct answer!

    The sloppy programmer does have a from clause in the next lines of code.
    We here at WHATS WRONG WITH THIS CODE think it has something to do with the quotes.
    If you get it right this time, you might move up to the next round.
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Okay I didn't know that one, BUT ...

    Here at smartbarstards Hq, weve just looked in the Wrox "professional SQL" book that shows samples of the HAVING clause after that of the FROM clause...

    Try swapping this around, if this don't work then I'm beat - your quote marks are fine

    Do I get any points for trying there though

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    You've been a great contestant!
    Tell him what he won, Bob

    Until next time
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width