string sql="select * from user where 1=1"; foreach(string str in Regex.Split(TextBox1.Text,"\\s+") { sql+= " AND name like %"+ str+"%"; }
;with cte([key]) as ( select 'sdfasdafsd' union all select 'sqwe534te' union all select '456456uyrty' union all select 'hgjf' union all select '45tyukuykxzvdfgaszl' ) select distinct [key] from (select a.[key],SUBSTRING([key],number,1) as chr from cte a,master..spt_values where number >=1 and type='p' and number<len([key]) )t where chr='a' or chr='z'/* key ---------------------------- sdfasdafsd 45tyukuykxzvdfgaszl */
foreach(string str in Regex.Split(TextBox1.Text,"\\s+")
{
sql+= " AND name like %"+ str+"%";
}
(
select 'sdfasdafsd'
union all select 'sqwe534te'
union all select '456456uyrty'
union all select 'hgjf'
union all select '45tyukuykxzvdfgaszl'
)
select distinct [key]
from
(select a.[key],SUBSTRING([key],number,1) as chr
from cte a,master..spt_values
where number >=1 and type='p' and number<len([key])
)t
where chr='a' or chr='z'/*
key
----------------------------
sdfasdafsd
45tyukuykxzvdfgaszl
*/