我有一些这样的数据。【dbo.Products】
Id        ProductName                      
 5   ST1041 Anti-RKIP Rabbit pAb
 6   Acetic Acid Glacial  冰乙酸
...然后进行模糊搜索
select *from dbo.Products where productname like '%Acetic Acid Glacial  冰乙酸%'
这个是没有问题的,但是搜索另一条数据
select *from dbo.Products where productname like '%ST1041 Anti-RKIP Rabbit pAb%'
无法搜索到,
最后我测试了下,原来数字和英文一起搜索是无法搜索到的,
请问各位这个怎么解决···

解决方案 »

  1.   

    这个不可能吧。应该是你中间多了空格什么的。
    用下边这个试试,不要那么多内容。
    select * from dbo.Products where productname like '%ST1041%' 
      

  2.   

    用trim方法去空格试试,不可能查不到呀
      

  3.   

    @smilysoft
    你那样是可以搜索到的,但是如果我把前面那几个数字替换成英文后,然后再搜索是没有问题的。
    比如这个原来数据是
    Id      ProductName
       33       ST36 PhosphoDetect? Anti-Raf (pSer
    我修改后为
    Id      ProductName
       33       STss PhosphoDetect? Anti-Raf (pSer
    然后
    select *from dbo.Products where productname like '%STss PhosphoDetect? Anti-Raf (pSer%'
    这样是有数据的···
      

  4.   

    @DBA_Huangzj   
    什么没在同一行上??
      

  5.   

    create table #A(Id int, ProductName nvarchar(50)) 
    insert into #A                     
     select  5 ,  'ST1041 Anti-RKIP Rabbit pAb' union all
      select 6  , 'Acetic Acid Glacial  冰乙酸'
      
      
      select * from #A where productname like '%ST1041 Anti-RKIP Rabbit pAb%'
    测试没有任务问题啊,估计是楼主数据有问题。
      

  6.   

    我的数据是从Excel中导入到数据库的。我也测试了#6那个方法,没有问题。这个和导入的数据会有问题吗?
      

  7.   

    那有可能,excel有很多数据没处理好的话会很怪异的,如果你的列不多,那么最好先插入一个临时表。然后在:
    insert into 目标表(列名)
    select convert(对应的列的类型,xx) ,....
    from 临时表
    这样避免存在格式上的错误,如果是字符型,可以加上那个ltrim(rtrim(convert(xxx)))这样来去除空格。
      

  8.   

    看看是不是编码的问题,从excel导入数据库,问题多多。
      

  9.   

    问题解决了额,是在Excel中出现了全角,然后入库就编码出错了。程序处理下就可以了···