Just for fun... try playing with parsename:** This is just an example. I didnt consider names like Michael J von Buren III
Props to Rob and Merkin Graz (sorry Graz
): [url]http://www.sqlteam.com/item.asp?ItemID=15044[/url]declare @table table (table_id int identity(1,1), defendant varchar(100))insert into @table (defendant) select 'Nathan L Skerl' union select 'Adam J Skerl' union select 'Natalie R Skerl' union select 'John Skerl'-- initial stateselect * from @table-- replace space with periodupdate @tableset defendant = case when LEN(LTRIM(RTRIM(defendant))) - LEN(REPLACE(LTRIM(RTRIM(defendant)), ' ', '')) = 2 then replace(defendant, ' ', '.') when LEN(LTRIM(RTRIM(defendant))) - LEN(REPLACE(LTRIM(RTRIM(defendant)), ' ', '')) = 1 then replace(defendant, ' ', '..') else defendant endselect parsename(defendant,3) as first_name, case when len(parsename(defendant,2)) = 1 then parsename(defendant,2) else null end as middle_initial, parsename(defendant,1) as last_namefrom @table
Nathan Skerl