【问题标题】:Does charindex count white spaces SQL Server 2014charindex 是否计算空格 SQL Server 2014
【发布时间】:2015-10-07 01:49:03
【问题描述】:

CharIndex 是否计算 SQL Server 2014 中的空格,如果计算,是否有替代 Charindex() 的方法来忽略空格?

我的意思是下面的例子。

select top 25 
    companyname, charindex ('A', companyname, 1) as 'occurences of a'
from shippers

结果看起来像

  • 极速快车 0
  • 联合包9
  • 联邦航运 6

我注意到,通过查看 United Package,它显示 9 计算空白区域,如果不是,则为 8。因此,如果有其他值得分享的替代方案,我们将不胜感激。

【问题讨论】:

    标签: sql sql-server-2014 charindex


    【解决方案1】:

    charindex 也会计算空格。

    您也可以使用空字符串replace 空格并搜索出现的字符。

    select top 25 companyname, 
    charindex ('A',replace(companyname,' ','')) as [occurences of a]
    from shippers
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-08
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多