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)
 SQL statement to replace "" for text

Author  Topic 

nt4vn
Yak Posting Veteran

98 Posts

Posted - 2008-06-26 : 20:25:24
Hello, How do I write a SQL statement that would replace "Text" to "". For example:

Mark William Jr
John Miller III
William Smith ESQ
--------
I would like to replace "" for ("Jr", "III", and "ESQ"). Please show my how to do it...Thanks,

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-06-26 : 20:28:10
replace(replace(replace(col, 'Jr', ''), 'III', ''), 'ESQ', '')


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

nt4vn
Yak Posting Veteran

98 Posts

Posted - 2008-06-26 : 21:04:21
quote:
Originally posted by khtan

replace(replace(replace(col, 'Jr', ''), 'III', ''), 'ESQ', '')


KH
[spoiler]Time is always against us[/spoiler]





Thanks very much!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-27 : 13:00:56
quote:
Originally posted by nt4vn

quote:
Originally posted by khtan

replace(replace(replace(col, 'Jr', ''), 'III', ''), 'ESQ', '')


KH
[spoiler]Time is always against us[/spoiler]





Thanks very much!


if you want to do this process for a large number of records without hardcoding do like this:-


SELECT REVERSE(SUBSTRING(REVERSE(Col),CHARINDEX(' ',REVERSE(Col))+1,LEN(Col)))

FROM Table
Go to Top of Page
   

- Advertisement -