How to return first letter of first name and last name.
I already know the substring
and the left
but if it has 2 names with different number of characters, it gives me wrong values.
-
Single column with delimited values?– Srini VMar 9, 2018 at 12:19
-
2some sample data will be appreciated– VenMar 9, 2018 at 12:21
-
Could you please tell the scenario if it has 2 names with different characters?– Yahya MukhtarMar 9, 2018 at 12:21
-
Which SQL Server version would help too. Could you have someone with 3 names, what about double barrelled? I.e. George Walker Bush and David Lloyd-George.– Thom AMar 9, 2018 at 12:22
-
1Add Malcolm McDowell, Conan O'Brien, Jonathan Rhys-Davies and Carl van der Walt to the sample data!– jarlhMar 9, 2018 at 12:23
|
Show 3 more comments
1 Answer
Something like this:
declare @a varchar(20)
set @a = 'John Smith'
select LEFT(@a,1) + substring(@a, charindex(' ', @a)+1 , 1)