表  a
id     address
001   湖南%长沙
002   湖南长沙想查询地址中含有%(百分号)的信息
select * from a where address like '%"%"%'
select * from a where address like '%%%'   都查不出来
请大家帮忙看下。

解决方案 »

  1.   

    declare @t table(id varchar(10),    address varchar(10))
    insert into @t select '001','湖南%长沙' 
    insert into @t select '002','湖南长沙'select * from @t where charindex('%',address) > 0  /*(1 row(s) affected)id         address    
    ---------- ---------- 
    001        湖南%长沙(1 row(s) affected)
    */
      

  2.   


    select * from @t where address like'%[%]%'
      

  3.   

    declare @t table(id varchar(10),address varchar(20)) 
    insert @t select '001',  '湖南%长沙' 
    insert @t select '002',  '湖南长沙'
    select * from @t where address like'%s%%'escape 's'id         address              
    ---------- -------------------- 
    001        湖南%长沙(所影响的行数为 1 行)
      

  4.   

    谢谢,懂了。
    但是还是想问下是不是用这种方式select * from a where address like  不能查出来。
       
      

  5.   

    if object_id('tb') is not null
       drop table tb
    go
    create table tb(id varchar(10),address varchar(20))
    go
    insert into tb
    select '001','湖南%长沙' union all
    select '002','湖南长沙'
    go
    select * from tb where charindex('%',address)>0
    select * from tb where address like '%[%]%'
    select * from tb where patindex('%[%]%',address)>0
      

  6.   

    select * from @t where address like'%[%%' ESCAPE '['
      

  7.   


    if object_id('表a') is not null
       drop table 表a
    go
    create table 表a
    ( id int,
      address nvarchar(10)
    )
    insert into 表a select 001,'湖南%长沙'
        union all   select 002,'湖南长沙'
    go
    select * from 表a where charindex('%',address)>0