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
 General SQL Server Forums
 New to SQL Server Programming
 Combine two scripts
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

VJG
Starting Member

USA
17 Posts

Posted - 10/09/2012 :  10:08:01  Show Profile  Reply with Quote
guys, thanks in advance for any help you can provide.


I have a field called firstname, which is in all CAPS. Also it contains first names and middle names. Ex. JOHN PAUL

I need to combine two scripts that I have.

1)
substring(Firstname,1,charindex(' ', Firstname)-1)
I'm only concerned about the first name

2)
firstname = convert(varchar(30),upper(substring(FirstName, 1,1))+lower(substring(FirstName, 2, 30)))
I need to get in in proper case.

my question, how do i combine both of these into one?

again thanks in advance for any help you can provide

malpashaa
Constraint Violating Yak Guru

Saudi Arabia
257 Posts

Posted - 10/09/2012 :  10:35:30  Show Profile  Reply with Quote
You can combine them like this:

firstname = convert(varchar(30),substring(upper(substring(FirstName, 1,1))+lower(substring(FirstName, 2, 30)) ,1,charindex(' ', Firstname)-1))


But a simpler way would be:
firstname = LEFT(FirstName, 1) + LOWER(SUBSTRING(FirstName, 2, CHARINDEX(' ', Firstname) - 2))




For us, there is only the trying. The rest is not our business. ~T.S. Eliot

Muhammad Al Pasha
Go to Top of Page

VJG
Starting Member

USA
17 Posts

Posted - 10/09/2012 :  10:40:28  Show Profile  Reply with Quote
Thanks Muhammad! I appreciate your help!

quote:
Originally posted by malpashaa

You can combine them like this:

firstname = convert(varchar(30),substring(upper(substring(FirstName, 1,1))+lower(substring(FirstName, 2, 30)) ,1,charindex(' ', Firstname)-1))


But a simpler way would be:
firstname = LEFT(FirstName, 1) + LOWER(SUBSTRING(FirstName, 2, CHARINDEX(' ', Firstname) - 2))




For us, there is only the trying. The rest is not our business. ~T.S. Eliot

Muhammad Al Pasha

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