0

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。因此,如果有其他值得分享的替代方案,将不胜感激。

4

1 回答 1

0

charindex也计算空格。

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

select top 25 companyname, 
charindex ('A',replace(companyname,' ','')) as [occurences of a]
from shippers
于 2015-10-07T01:51:19.240 回答