Solved

Firstnames

Posted on 2013-05-23
10
161 Views
Last Modified: 2013-05-27
issues with middle name

in one column I  have a firstname and a middle name

Gwenda agnes
Pamela joyce
Jocelyn ruth
Gregory ian
Cheryl joy

and sometimes  just one name
John

Where you have two names in the firstname column how do you get it to appear as

Gwenda Agnes

If there is only one space between the next name?
0
Comment
Question by:Amanda Walshaw
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
hope this helps :

link
0
 

Author Comment

by:Amanda Walshaw
Comment Utility
sorry page not found
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
http://www.devx.com/tips/Tip/17608 (worked for me)

It's an "Initial Capitals" function
0
 

Author Comment

by:Amanda Walshaw
Comment Utility
sorry its taking me to an advertisment about registering in San francisco
0
 

Author Comment

by:Amanda Walshaw
Comment Utility
-update Staging_mytable
set firstname = Replace(Firstname,reverse(left(reverse(firstname),len(firstname)-1)),  reverse(lower(left(reverse(firstname),len(firstname)-1))))      ,


I have used this query but I am getting struck by the middle name, it is consistent with one space.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
i have copied the script into .txt file from the link .... its a same link that PortletPaul has posted.
notepad.txt
0
 
LVL 16

Assisted Solution

by:santoshmotwani
santoshmotwani earned 250 total points
Comment Utility
do you want to try this :

update Staging_mytable
set firstname = Replace(Firstname,reverse(left(reverse(firstname),len(firstname)-1)) + ' ' + reverse(lower(left(reverse(firstname),len(firstname)-1))))
0
 

Author Comment

by:Amanda Walshaw
Comment Utility
update dbo.mytable
set firstname = Replace(Firstname,reverse left(reverse(firstname),len(firstname)-1)))) + ' ' + reverse(lower(left(reverse(firstname),len(firstname)-1)))
where Firstname = 'Kym dianne'
and LastName = 'Spoors'

unfortunately getting error message
The replace function requires 3 argument(s).
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 250 total points
Comment Utility
Your parenthesis are all wrong in comparison to the solution posted.  This is more like the solution posted (no points please):
UPDATE  dbo.mytable
SET     firstname = REPLACE(Firstname, REVERSE(LEFT(REVERSE(firstname), LEN(firstname) - 1)) + ' ' + REVERSE(LOWER(LEFT(REVERSE(firstname), LEN(firstname) - 1))))
WHERE   Firstname = 'Kym dianne'
        AND LastName = 'Spoors'

Open in new window


Caveat: I have no idea if this accomplishes your task (I would never use T-SQL for this) I am merely correcting the syntax.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
So much for "no points please".  Oh well ...
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now