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() one instance???

Author  Topic 

skb3
Starting Member

2 Posts

Posted - 2007-11-29 : 06:29:03
Could anyone help me here I have products in a table, but I need to select a distinct list, the list contains the following:

Contract Purchase Advance Advance
Hire Purchase Advance Advance
Hire Purchase Arrears
Finance Lease Advance

In the case of the first couple of lines I need to replace only 1 instance of 'Advance' not both. Is there anyway I could do this, I know the Replace() function does not replace only one instance, i.e.

Select Replace(ProductNames, 'Advance', '') from ProductList

Would removed both instances, could anyone help me please?

Thanks in Advance,

Steve

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-29 : 07:17:05
Try


select case when ProductNames like '%advance advance%' then replace(ProductNames,'advance advance','advance') else replace(ProductNames ,'advance','') end from ProductList


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

skb3
Starting Member

2 Posts

Posted - 2007-11-29 : 09:04:01
Thanks very much Madhivanan, that's a great idea, I have a few extra case statements, but I have it all working now. Fantastic.
Go to Top of Page
   

- Advertisement -