SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 replace function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aakcse
Aged Yak Warrior

India
517 Posts

Posted - 07/17/2012 :  05:46:36  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8514 Posts

Posted - 07/17/2012 :  06:44:18  Show Profile  Visit webfred's Homepage  Reply with Quote
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

India
47099 Posts

Posted - 07/17/2012 :  09:59:24  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 07/17/2012 :  13:45:45  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000