Jump to content

database select statement with variable


Recommended Posts

I am trying to use a query based on the users input. I want them to enter a portion of the customers name which then creates the qurey. Is this the correct way to accomplish this or is there a better way to do it?

Do

$strName = InputBox("Input","Enter all or part of a company name to search for:",""," M")

Until $strName <> ""

$DB = @ScriptDir & "\customers.mdb"

I have tried these:

$Query= "SELECT CompanyName,CompanyAddress1,CompanyCity,CompanyState FROM CompanyName WHERE CompanyName LIKE '$strName%' ORDER BY CompanyName Asc"

$Query= "SELECT CompanyName,CompanyAddress1,CompanyCity,CompanyState FROM CompanyName WHERE CompanyName LIKE ' & $strName & % & ' ORDER BY CompanyName Asc"

$Query= "SELECT CompanyName,CompanyAddress1,CompanyCity,CompanyState FROM CompanyName WHERE CompanyName LIKE ' $strName & % ' ORDER BY CompanyName Asc"

Any advice?

CC

Link to comment
Share on other sites

I am trying to use a query based on the users input. I want them to enter a portion of the customers name which then creates the qurey. Is this the correct way to accomplish this or is there a better way to do it?

Do

$strName = InputBox("Input","Enter all or part of a company name to search for:",""," M")

Until $strName <> ""

If the entered value was Thom, then you want the CompanyName string to be like Thom% (starts with), so it would match "Thomas" for example.

Looks more to me like it would be:

$Query= 'SELECT CompanyName,CompanyAddress1,CompanyCity,CompanyState FROM CompanyName WHERE CompanyName LIKE ' & $strName & '% ORDER BY CompanyName Asc"

:D

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I get an unterminated string error when I attempted your suggestion. I did finally get the query to work :-) when I used the following:

$Query= "SELECT CompanyName,CompanyAddress1,CompanyCity,CompanyState FROM CompanyName WHERE CompanyName LIKE " & "'" & $strName & "%' " & "ORDER BY CompanyName Asc"

I just pieced the query together with &'s to get my syntax correct.

CC

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...