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)
 removing data

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-01-13 : 07:52:31
Garry writes "I have a last name field that contains data after the name such as ad-1222, ahtto. At time there is no data after the name. I want to remove everything after the name. Field could be,
Johnson
Johnson AD-45445
Johnson,
Johnson agtee
Each field should be
Johnson

Thanks."

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-01-13 : 07:56:27
SELECT SubString(LastName, 1, PatIndex('%[^a-z]%', LastName)-1) FROM myTable

Last names like St. Clair, O'Donnell, hyphenates, etc., will not work with this query though.
Go to Top of Page
   

- Advertisement -