如:A表  tag 字段
现在输入   北京  三环   XX街
我想在产品tag中找到含有有上面三个关键字的数据,需要sql语句处理。

解决方案 »

  1.   

    select * from a where tag like '%北京' and tag like '%三环' and tag like '%XX街' 
      

  2.   

    where charindex('北京',Tag)>0 and charindex('三环',Tag)>0 and charindex('XX街',Tag)>0
    这里是用and 还是or 就看你是什么关系了
      

  3.   

    select * from a 
    where charindex('北京',Tag)>0 and charindex('三环',Tag)>0 and charindex('XX街',Tag)>0
      

  4.   

    like的效率不是很高的,但实现楼主的具体要求。
      

  5.   

    多关键字查询
    charindex('北京 三环 XX街',Tag)>0
      

  6.   

    select * from a 
    where charindex('北京',Tag)>0 and charindex('三环',Tag)>0 and charindex('XX街',Tag)>0
      

  7.   


    --只能这样,先
    select * from a where 1=1
    --然后根据传入的值按固定分隔符拆分出来,比如你那里的空格为例,拆分后有几个and几个条件
    --and charindex('北京',Tag)>0 
    --and charindex('三环',Tag)>0 
    --and charindex('XX街',Tag)>0
      

  8.   

    where charindex(name,'北京 三环 XX街')>0
      

  9.   


    有多有少在后台做拼接! if(col1!="")
    {
     sql=sql+"and tag like '%"+"三环"+"' "
    }.....有多少拼多少!
      

  10.   

    declare @a varchar(10) 
    declare @s varchar(1000)
    declare @t table(name varchar(10))
    set @a='a,b,c'
    set @s=right(replace(','+@a,',',''' as name union select '''),len(replace(','+@a,',',''' as name union select '''))-15)+''''
    insert into @t exec(@s)
    select * from tb b where exists
    (select 1 from @t a where charindex(a.name,b.name)>0)
      

  11.   

    select * from a 
    where charindex('北京',Tag)>0 and charindex('三环',Tag)>0 and charindex('XX街',Tag)>0
      

  12.   

    declare @a varchar(10) 
    declare @s varchar(1000)
    declare @t table(name varchar(10))
    set @a='a,b,c'
    set @s=right(replace(','+@a,',',''' as name union select '''),len(replace(','+@a,',',''' as name union select '''))-15)+''''
    insert into @t exec(@s)
    select * from tb b where exists
    (select 1 from @t a where charindex(a.name,b.name)>0)