Sql Server全局模糊查询,非like or

全局模糊查询,实战版
主要用到charindex(a,b)是一个数据库函数
直接上代码
我的实例是一个前端多页签,指定条件查询+模糊查询
SQL:select * from table where
a= 1 //其他条件
and (charindex(传入的参数,字段名)>0 or charindex(传入的参数,字段名)>0)//模糊条件
看懂可以直接用,看不懂请看图例

Sql Server全局模糊查询,非like or
前端swich case 123
swich case 查询条件

后端
StringBuilder str = new StringBuilder();
str.Append(@“select * from TABLE”);
str.AppendFormat(" where TYPE = {0}", type);
if (status != null && status.Trim() != “”)
{
str.AppendFormat(" and MRGA_STATUS = {0}", status);
}
if (selectstr != null && selectstr.Trim() != “”)
{
str.AppendFormat(@" and (charindex(’{0}’,NAME)>0 or
charindex(’{0}’,CODE)>0 or
charindex(’{0}’,NUMBER)>0 or
charindex(’{0}’,STATUS)>0 or
charindex(’{0}’,CODE)>0 or
charindex(’{0}’,TIME)>0 or
charindex(’{0}’,PERSON)>0 or
charindex(’{0}’,DEPARTMENT)>0 or
charindex(’{0}’,WATERCODE)>0 or
charindex(’{0}’,WATER)>0 or
charindex(’{0}’,CUSTOMERNAME)>0 or
charindex(’{0}’,MRGA_DELIVERY_DESTINATION)>0)", 模糊);
}