I have a table with approx 1200 names in the format of "John Doe" I need to edit the names to the format of "Doe, John"
Any easy way in SQL to do this or am I better off dumping to text file, making the changes in another app and then updating the table?I guess in some time you'll need another format - "FN Doe LN John" ;). It is better to keep first and last name in different fields.|||Your lucky day. See attached file with function for parsing names.|||Yes, Separate columns would be better.
USE Northwind
GO
SET NOCOUNT ON
CREATE TABLE myTable99(myName varchar(50))
GO
INSERT INTO myTable99(myName)
SELECT 'John Doe' UNION ALL
SELECT 'John Apple' UNION ALL
SELECT 'John Q. Adams' UNION ALL
SELECT 'Mr. John Doe' UNION ALL
SELECT 'John Doe III'
GO
SELECT SUBSTRING(myName,(CHARINDEX(' ',myName)+1),(LEN(myName)-(CHARINDEX(' ',myName)))) + ', '
+ SUBSTRING(myName,1,(CHARINDEX(' ',myName)-1))
FROM myTable99
GO
SET NOCOUNT OFF
DROP TABLE myTable99
GO
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment