Reputation: 559
I want to write an SQL query using the LIKE
keyword. It should search the first character or the starting character of my column with the search parameter.
Is there a specific syntax for doing this?
Upvotes: 2
Views: 2786
Reputation: 338406
For a parameterized query, which you seem to have ("search the first character [...] with the search parameter"), use this:
SELECT *
FROM yourtable
WHERE yourcolumn LIKE ? + '%'
Upvotes: 1
Reputation: 251262
Here's two examples...
SELECT FirstName
FROM tblCustomer
WHERE FirstName LIKE 'B%'
The % sign is the wildcard, so this would return all results where the First Name starts with B.
This might be more efficient though...
SELECT FirstName
FROM tblCustomer
WHERE LEFT(FirstName, 1) = 'B'
Upvotes: 1
Reputation: 581
Try
select * from table where column like 'c%'
where 'c' is the character you want
Upvotes: 3
Reputation: 391724
Is this what you're looking for
SELECT *
FROM yourtable
WHERE yourcolumn LIKE 'X%'
This will find all rows where yourcolumn
starts with the letter X.
To find all that ends with X:
...
WHERE yourcolumn LIKE '%X'
...and contains an X...
...
WHERE yourcolumn LIKE '%X%'
Upvotes: 9