表 tt
id   name  cnt
1     aa    89
2     bb    10
3     cc    80我想 通过  cc972   找到  第3条记录貌似 select * from tt where ‘cc973’ like '%'+'name'+'%'
但是这么写不行。

解决方案 »

  1.   

    select * from tt where charindex(name,‘cc973’)>0
      

  2.   

    select * from tt where 'cc973' like '%'+name+'%'
      

  3.   

    select * from tt where charindex(name,'cc973')>0
      

  4.   

    name是一个字段名,把两边的单引号去掉。
      

  5.   

    select * from tt where 'cc973' like '%'+name+'%'
      

  6.   

    难道   又   是版本支持问题。。
    我的是
    mysql4.0
    用 select * from tt where 'cc973' like '%'+name+'%'
    所有记录都出来了
    用 select * from tt where 'cc973' like '%'+'name'+'%'
    什么也出不来 但是都不报错
    charindex  不支持555555
    谢谢大家!!我想那都是正解!!
    公司 就这情况不升级软件。