[英]SQL Server 2005 Query SUBSTRING & PATINDEX
我的数据库中有三个单词短语:
例如:“ JKH排水装置”
有谁知道如何获得第三个单词的第一个字母?
我需要提取“单位”一词的“ U”。
注意我尝试使用SUBSTRING(Phrase,PATINDEX('%%%',Phrase)+ 1,1)但对我不起作用...
我将其逐步分解,只是为了让我疯狂地展示这种方法:
declare @Phrase varchar(100)
set @Phrase = 'JKH Drainage Units'
/* The first space */
select charindex(' ', @Phrase, 1)
/* The second space */
select charindex(' ', @Phrase, charindex(' ', @Phrase, 1) + 1)
/* The first character after the second space */
select substring(@Phrase, charindex(' ', @Phrase, charindex(' ', @Phrase, 1) + 1)+1, 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.