Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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 ?
 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
352 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
52326 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  
 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.17 seconds. Powered By: Snitz Forums 2000