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.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 SQL Query ?

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 Doe
Mary Thomas
James Kerry

Output:

JDoe
MThomas
JKerry

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-12 : 11:38:00
[code]STUFF(yourCol,2,CHARINDEX(' ',yourCol)-1,'')[/code]
Go to Top of Page

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 Karney

I want it to be TKarney.

Go to Top of Page

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]
Go to Top of Page

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.
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -