简体   繁体   English

SQL Server 2005查询SUBSTRING和PATINDEX

[英]SQL Server 2005 Query SUBSTRING & PATINDEX

i have in my database three word phrases: 我的数据库中有三个单词短语:

for example: "JKH Drainage Units" 例如:“ JKH排水装置”

Does anyone knows how to get the first letter of the third word? 有谁知道如何获得第三个单词的第一个字母?

i need to extract the "U" of the "Units" word. 我需要提取“单位”一词的“ U”。

NB i tried to use SUBSTRING(Phrase, PATINDEX('% % %', Phrase) + 1, 1) but it didn't work for me... 注意我尝试使用SUBSTRING(Phrase,PATINDEX('%%%',Phrase)+ 1,1)但对我不起作用...

I've broken it down step-by-step, just to show the method to my madness: 我将其逐步分解,只是为了让我疯狂地展示这种方法:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM