you can do this, first create this method:
public static string GetLike(string input)
{
string[] sa = input.Split(' ');
var sb = new System.Text.StringBuilder();
sb.Append("'");
foreach (string s in sa)
{
sb.Append("%" + s);
}
sb.Append("%'");
return sb.ToString();
}
Then, we can use it like this:
private string GenerateSQL(string searchThis)
{
string sql = "select * from `tablename` where `columnname` like "
+ GetLike(searchThis) + ";";
}
In this case, if you want to search "ab-cd-ef" and "abcdef", you do it like this
GenerateSQL("ab cd");
and this will be generated:
select * from `tablename` where `columnname` like '%ab%cd%';
you will be able to get both. (
ab-cd-ef
and
abcdef
)