Another SQL Parsing

Last Post 21 Oct 2008 10:44 AM by GoodFella3993. 2 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
GoodFella3993
New Member
New Member

--
21 Oct 2008 09:40 AM
I have a table with contact information. There are two fields for last name. [LName1] and [LName2].

When LName1 contains the word Van (IE: Van Pelten) then the LName2 field should be populated with 'Van' and the LName1 field should only have the word 'Pelten'

Incomming:
LName1______LName2
Van Pelton ___ NULL

Outgoing:
LName1______LName2
Pelton _______ Van

Thanks again,
Marc
nosepicker
New Member
New Member

--
21 Oct 2008 10:28 AM
One way to update the LName2 column:

UPDATE YourTable
SET LName2 = SUBSTRING(LName1, CHARINDEX(' ', LName1) +1, LEN(LName1))
WHERE LName1 LIKE 'Van %'

GoodFella3993
New Member
New Member

--
21 Oct 2008 10:44 AM
That looks great NP! How would you go about removing the 'VAN' from Lname1?

Thank You.
You are not authorized to post a reply.

Acceptable Use Policy