-
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!?!?!
-
wow 500 points :cool:
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 ?
-
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.
-
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 :D
-
You've been a great contestant!
Tell him what he won, Bob
Until next time