mysql WHERE statement problem

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
garyds
Posts: 7
Joined: Fri Oct 20, 2017 8:44 pm

mysql WHERE statement problem

Post by garyds » Fri Oct 20, 2017 9:08 pm

Hi All,

First off I hope this is the correct area to post this question as I wouldn't want to be cluttering the forum.

I was wondering if anybody could help regarding a MySql statement, this particular query has been driving me crazy for the past two days. I'm trying to include a variable within the WHERE statement allowing the user to edit what is searched for.

Here is a snippet of my code:

Code: Select all

put "SELECT tbl_one.*,tbl_two.mpn, tbl_two.cost_price, tbl_two.list_price  FROM tbl_one,tbl_two " & \
         "WHERE tbl_one.mpn = tbl_two.mpn" & vUserInput &  "" into tQuery
I'm essentially trying to get a match across tbl_one & tbl_two (Which I have running via other scripts) and then including the "vUserInput" enhancing the WHERE statement acting like an AND ("WHERE tbl_one.mpn = tbl_two.mpn and tbl_one.mpn = vUserInput).As it would perform in a normal MySql query.

I hope this makes sense to someone, I feel that this is somewhat easy and I'm completely overlooking it and or being an idiot.

Any help would be greatly appreciated.

Gary

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: mysql WHERE statement problem

Post by Klaus » Fri Oct 20, 2017 9:23 pm

Hi garyds,

1. welcome to the forum! :D

2. You need to QUOTE the variable like:

Code: Select all

...
put "SELECT tbl_one.*,tbl_two.mpn, tbl_two.cost_price, tbl_two.list_price  FROM tbl_one,tbl_two " & \
         "WHERE tbl_one.mpn = tbl_two.mpn AND tbl_one.mpn=" & QUOTE & vUserInput & QUOTE into tQuery
...
The empty quotes at the end of your query do not make sense.
Hope I understood your problem correctly!


Best

Klaus

garyds
Posts: 7
Joined: Fri Oct 20, 2017 8:44 pm

Re: mysql WHERE statement problem

Post by garyds » Fri Oct 20, 2017 10:11 pm

Hello Klaus and thank you!

I wasn't to sure on the correct syntax and ended up in a mix. This has helped me solve a two day long problem.

Thanks for your prompt reply. :D

Gary

Post Reply

Return to “Databases”