Link to home
Start Free TrialLog in
Avatar of FaheemAhmadGul
FaheemAhmadGulFlag for United Kingdom of Great Britain and Northern Ireland

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"
Dim strSelectClients  As String
Dim searchPhrase As String
searchPhrase = "ch"
 strSelectClients = "Select * from Clients where FirstName like '%" & searchPhrase & "%' "

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sujith
Sujith
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of FaheemAhmadGul

ASKER

This worked perfectly. Many thanks.
You are welcome.