Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Parsing script needed for name records

Author  Topic 

RML51
Starting Member

2 Posts

Posted - 2005-01-07 : 15:14:45
We have a table of names that has 3 columns (first| middle init | last).
Some records were imported into the table incorrectly, so we now have some first name columns that contain both the first name and middle init. For example:

ColFirstNm MI ColLastName
|Aaron B. | |Lastname |
|Betty C. | |Lastname |

should be:

|Aaron |B.|Lastname |
|Betty |C.|Lastname |

Does anyone know of an easy way to fix this?

Thanks

Kristen
Test

22859 Posts

Posted - 2005-01-08 : 07:15:00
[code]
UPDATE U
SET
-- SELECT [OriginalData] = ColFirstNm,
MI = LEFT(RIGHT(ColFirstNm, 2), 1),
ColFirstNm = LEFT(ColFirstNm, DATALENGTH(ColFirstNm)-3)
FROM MyTable U
WHERE MI IS NULL
AND ColFirstNm LIKE '% [A-Z].'
[/code]
I suggest you just run from the "--" to the end as a test first!!

Kristen
Go to Top of Page

RML51
Starting Member

2 Posts

Posted - 2005-01-10 : 08:58:03
Thanks Kristen, I'll give it a try.
Go to Top of Page
   

- Advertisement -