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 characters in certain positions

Author  Topic 

KelCook
Starting Member

5 Posts

Posted - 2004-11-18 : 14:47:39
I have a field that returns book subjects like this:
|Act/Advent|Adop/Orp|Boy|Environmnt|Parent|
Seperates the different subjects by |.

I want to strip out the | and replace the ones inbetween with commas. IF it didnt have the leading and ending | I dont think it would be such a hassle. I would like it to end up looking like this.
Act/Advent, Adop/Orp, Boy, Environmnt, Parent


Any help would be appreciated!
Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-11-18 : 15:02:30
DECLARE @String varchar(7000)

SET @String = '|Act/Advent|Adop/Orp|Boy|Environmnt|Parent|'

SELECT REPLACE(SUBSTRING(@String, 2, LEN(@String) - 2), '|', ',')

Tara
Go to Top of Page

KelCook
Starting Member

5 Posts

Posted - 2004-11-18 : 15:06:30
Works Perfectly!!
Thanks Tara!
Go to Top of Page
   

- Advertisement -