2016年1月6日 星期三

Searching in SQL Multiple Keyword in a Field

Searching in SQL Multiple Keyword in a Field


Filter: OR
string str = "john,jack,alton";

string select = "SELECT * FROM [TableName] WHERE [UserName] LIKE ''%' + REPLACE(str , ',' , '%'' OR [UserName] LIKE ''%') + '%''";


Filter: AND
string str = "john,jack,alton";

string select = "SELECT * FROM [TableName] WHERE [UserName] LIKE ''%' + REPLACE(str , ',' , '%'' AND [UserName] LIKE ''%') + '%''";


ref url:
http://forums.asp.net/t/1683482.aspx?Sql+query+to+search+database+with+multiple+keywords

沒有留言:

張貼留言