I have a column in a table that contains a full name value like this: Foster, Lorenzo E I would like to take all the values from this column...

How It Works

Get an answer in three easy steps. Here's how it works...

Ask Your Question

1. Ask Your Question

Enter your programming question at the top of this page and click Get An Answer.

Pick Your Priority

2. Pick Your Priority

Tell us how quickly you want your programming question answered.

Get An Answer

3. Get An Answer

Connect with your programmer via online chat or telephone call.

Answer

Customer
I have a column in a table that contains a full name value like this: Foster, Lorenzo E I would like to take all the values from this column titled am_mgr_nm, (they are employee full names) from this table, called T_Accounting Unit, (which holds the values like the example above) and seperate the last name from the First Name and middle initial while dropping the comma. I then need to insert these 2 seperate values into a table called T_TeamMember with the columns titled tm_first_nm and tm_lst_nm respectively with their respective values. I know it's not concatenate, but i am unable to find how to do this. Can anyone point me to a turorial or help me out? Lorenzo
Posted
Matthew Pomar
Customer Support
There isn't a simple explaination for this. However, I'll try my best: I don't know if I understand anymore about your problem other than the fact you must split the name. Here's How I would do it: 1. To get the last name, I would use CHARINDEX to locate the position of the comma. Then using LEFT, you can scrape the last name out. 2. To get the first name, I would use SUBSTRING and use 1 + the position of the comma, and -2 the LEN of the string. 3. Finally the midde initial. I would simply use the RIGHT function. SQL Server makes it pretty easy with all the wonderful funtions. To see how to use these functions, launch SQL Server Books Online (not the internet) and look up String Functions (T-SQL) in the index. Hope this helps! Regards, Matthew Pomar
Posted
Matthew Pomar
Customer Support
Woops, I think I might have read your questions wrong. Here's how I would do it: Select [FirstName] + " " + [LastName] As FullName From Members I've tested this and it works. Regards, Matthew Pomar
Posted
Customer
Thanks, I meant to send you an email. I solved the problem, the syntax is like so... CREATE TABLE #tblSource(name varchar(255)) -- source table CREATE TABLE #tblDest(lname varchar(255),fname varchar(255)) -- destination table INSERT INTO #tblSource VALUES('Foster,Estevan L') INSERT INTO #tblSource VALUES('Foster, Judie J') INSERT INTO #tblSource VALUES('Gates,Bill X') INSERT INTO #tblSource VALUES('Brown, Jacob') INSERT INTO #tblSource VALUES('Brown,Eva K') INSERT INTO #tblDest SELECT LEFT(name,CHARINDEX(',',name)-1), LTRIM(RIGHT(name,LEN(NAME)-CHARINDEX(',',name))) FROM #tblSource SELECT * FROM #tblSource DROP TABLE #tblSource SELECT * FROM #tblDest DROP TABLE #tblDest
Posted

quoteTestimonialsquote

About ExpertHelp

ExpertHelp is changing the way you connect with service professionals.

Whether you have a quick question while preparing your taxes, troubleshooting a computer problem, or need to hire an attorney, ExpertHelp is the most convenient and affordable way to connect with the right service professional to get the job done.

ExpertHelp has been in business since 2011, is an A+ Rated Better Business Bureau accredited member, and offers a 100% satisfaction guarantee on every question you ask!

More Programming Questions...

Ask Your Programming Question & Get An Answer Now!