1

i have in my database three word phrases:

for example: "JKH Drainage Units"

Does anyone knows how to get 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...

Joy
  • 45
  • 1
  • 4
  • Define "word". Or do you just mean the first non-space character after the second space regardless of whether or not it is part of a "word"? – Mark Byers Jan 13 '11 at 20:55
  • the first none-space character after the second space... you said it better than me :) – Joy Jan 13 '11 at 20:57

1 Answers1

0

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)
Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235