Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sqldba20
Posting Yak Master
183 Posts |
Posted - 2012-12-12 : 11:24:27
|
We have a table which stores the FullNames of all users. I would like to get the first character of the FIRST NAME and all characters of the Last Name. There is a space between both those names.John DoeMary ThomasJames KerryOutput:JDoeMThomasJKerry |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-12-12 : 11:38:00
|
[code]STUFF(yourCol,2,CHARINDEX(' ',yourCol)-1,'')[/code] |
|
|
sqldba20
Posting Yak Master
183 Posts |
Posted - 2012-12-12 : 11:51:53
|
I just noticed we also have a user like this:Tm. Mike KarneyI want it to be TKarney. |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-12-12 : 12:25:29
|
[code]LEFT(yourCol,1)+REVERSE(LEFT(REVERSE(yourCol),CHARINDEX(' ',REVERSE(yourCol))-1))[/code] |
|
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2012-12-13 : 13:26:12
|
Working with names will get messy quick. What if you have Jack De Salvo? Jack Kennedy Jr.?Good luck. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-12-14 : 03:14:48
|
The best thing is to first analyse how all patterns can come and then formulating a rule for each. Might have to apply separate logic for each set to get intended result------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|