FaheemAhmadGul
asked on
Help with an SQL Statement that uses a variable for a fieldName value
I need help with an SQL Statement in which I am using Like. I would like to Select all records where the FirstName starts with the letters "ch"
However, in the SQL statement I need put the letters "ch" using a variable named SearchPhrase.
The SQL Statement in the code window selects for me all records which the letter combination "ch" occurs any where in the FirstName Field. I would like to Select only records where FirstName field starts with "ch"
However, in the SQL statement I need put the letters "ch" using a variable named SearchPhrase.
The SQL Statement in the code window selects for me all records which the letter combination "ch" occurs any where in the FirstName Field. I would like to Select only records where FirstName field starts with "ch"
Dim strSelectClients As String
Dim searchPhrase As String
searchPhrase = "ch"
strSelectClients = "Select * from Clients where FirstName like '%" & searchPhrase & "%' "
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I.e. You don't need the first % if you are looking for names starting with your search Phrase. You only need to wild card(%) the ending portion
ASKER
This worked perfectly. Many thanks.
You are welcome.