SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 SQL Query ?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqldba20
Posting Yak Master

183 Posts

Posted - 12/12/2012 :  11:24:27  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/12/2012 :  11:38:00  Show Profile  Reply with Quote
STUFF(yourCol,2,CHARINDEX(' ',yourCol)-1,'')
Go to Top of Page

sqldba20
Posting Yak Master

183 Posts

Posted - 12/12/2012 :  11:51:53  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/12/2012 :  12:25:29  Show Profile  Reply with Quote
LEFT(yourCol,1)+REVERSE(LEFT(REVERSE(yourCol),CHARINDEX(' ',REVERSE(yourCol))-1))
Go to Top of Page

djj55
Constraint Violating Yak Guru

USA
327 Posts

Posted - 12/13/2012 :  13:26:12  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 12/14/2012 :  03:14:48  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000