开发者

SQL Server 2005 Query SUBSTRING & PATINDEX

i have in my database three word phrases:

for example: "JKH Drainage Units"

Does anyone knows how to ge开发者_如何学编程t the first letter of the third word?

i need to extract the "U" of the "Units" word.

N.B. i tried to use SUBSTRING(Phrase, PATINDEX('% % %', Phrase) + 1, 1) but it didn't work for me...


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜