sqllike语句:SQL中代替Like语句的写法



比如查找用户名包含有"c"所有用户, 可以用

  use mydatabase
  select * from table1 where username like'%c%"


  下面是完成上面功能种写法:
  use mydatabase
  select * from table1 where charindex('c',username)gt;0
  这种思路方法理论上比上种思路方法多了个判断语句,即gt;0, 但这个判断过程是最快, 我想信80%以上运算都是花在查找串及其它运算上, 所以运用charindex也没什么大不了. 用这种思路方法也有好处, 那就是对%,|等在不能直接用like查找到中可以直接在这charindex中运用, 如下:
  use mydatabase
  select * from table1 where charindex('%',username)gt;0
  也可以写成:
  use mydatabase
  select * from table1 where charindex(char(37),username)gt;0
  ASCII即为%
Tags:  like语句 sql语句like的用法 sql语句中的like sqllike语句

延伸阅读

最新评论

发表评论