SQL select statement - returning records starting with variable length string

Posted by alpheus on Stack Overflow See other posts from Stack Overflow or by alpheus
Published on 2010-05-27T16:33:41Z Indexed on 2010/05/27 16:41 UTC
Read the original article Hit count: 210

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about sql