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
 General SQL Server Forums
 New to SQL Server Programming
 replace function

Author  Topic 

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-07-17 : 05:46:36
In a column I want to replace the second occurance of single char '/' with char(32) I,e. space.

How can I do so?

I am able to locate that value but not able to replace I have a function "count_char" to find the number of rec which has '/' more than once

update #table1 set col1= Replace...
where CountChar(lump,'/')>1

I am able to locate that char by using below string fun

SUBSTRING(col1,charindex('/',col1, CHARINDEX('/',col1,1)+1),1)


-Neil

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-07-17 : 06:44:18
If you are able to locate the position of that char then have a look at STUFF()


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-17 : 09:59:24
see

http://itdeveloperzone.blogspot.com/2012/03/find-nth-occurrence-of-character-sql.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-07-17 : 13:45:45
No need for the function.
Something like

update #table1
set col1= stuff(col1,charindex('/',col1, CHARINDEX('/',col1,1)+1),1,'')
where len(replace(lump,'/','')+'|') - len(lump+'|') > 1



==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -