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
 General SQL Server Forums
 New to SQL Server Programming
 Combine two scripts

Author  Topic 

VJG
Starting Member

17 Posts

Posted - 2012-10-09 : 10:08:01
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

264 Posts

Posted - 2012-10-09 : 10:35:30
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

17 Posts

Posted - 2012-10-09 : 10:40:28
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
   

- Advertisement -