SQL select statement - returning records starting with variable length string
- by alpheus
I am using an alphabetical sorting feature and need a SQL statement to return records beginning with a variable length string. However, records also need to be returned if there are periods, spaces, or dashes between any of the characters in the string.
For example, the string could be "M" (easy). Or "MA" (in which case it needs to return records starting with "MA", "M.A", "M A", and "M-A"). Or "MAA", and so on.
This is the statement I have so far:
"SELECT * from table where LEFT(name," + value.Length + ")='" + value + "'"
But I can't work out how to get it to return results where there are periods, spaces or dashes in name. Any help constructing the statement would be great.