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 2005 Forums
 Transact-SQL (2005)
 Replace a pipe character with a empty character?

Author  Topic 

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-08-15 : 10:17:37
Hi All,

I have a Table called Product with the following fields.

UPC nvarchar(12)
Category nvarchar(50)
SubCategory nvarchar(50)
Department nvarchar(50)
Brand nvarchar(50)


In my select I want to return everything (all columns) but if there's any pipe | character in the Brand column I want to replace that character with a empty character. Following is an example.

Let suppose the following 3 records exists (records are seperated by comma). Please notice the Brand records.

UPC,Category,SubCategory,Department,Brand
012345678901,012477,477,9876,Pepsi| Lime
01236518901,023570,570,67000,Kellogs|| Essential||
987449236,987210,7210,8855,Bacardi Si|lver |

My select should return the following.
UPC,Category,SubCategory,Department,Brand
012345678901,012477,477,9876,Pepsi Lime
01236518901,023570,570,67000,Kellogs Essential
987449236,987210,7210,8855,Bacardi Si lver

How can I do this?

Please help.

Thanks a million for your quick help.

Zee

cardgunner

326 Posts

Posted - 2008-08-15 : 10:29:13
Have you tried the replace function

replace(yourtablename.Brand, '|', '')

CardGunner
Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-08-15 : 10:41:13

Thanks cardgunner for your help.

The following is working :)
select ID, Brand, replace(Product.Brand, '|', '') Brand from product
Go to Top of Page
   

- Advertisement -