Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to replace multiple different characters('+','-','/','(',')') in single replace function.
i know using replace(replace(replace(replace(ssdsdsd,se,we) bu,t want in single replace.
plzz anyone can help me??
Posted
Comments
manognya kota 16-Feb-12 0:16am    
Can you exactly tell what all you want to replace with what?
thatraja 16-Feb-12 0:33am    
Show full code/query
rajdeep kumar 16-Feb-12 0:34am    
Hi,
i want to replace this number +(60) 2345(0)-324 into 6023450324
with only single replace function.
rajdeep kumar 16-Feb-12 0:40am    
this is my number= +(60) 2345(0)-324
i used this query to replace all characters with ''
LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(OffPhoneNo,' ',''),'.',''),'-',''),'+',''),'(',''),')',''),CHAR(9),'')))

so is there other way to replace this numer with single replace function???

Better way is create an User defined function[^] with those many Replaces & ans use it in your SQL SELECT statement

EDIT
SQL
CREATE FUNCTION Fn_Phone
(
    @OffPhoneNo VARCHAR(100) 
)
    RETURNS VARCHAR(100)
AS
BEGIN
  RETURN(LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@OffPhoneNo,' ',''),'.',''),'-',''),'+',''),'(',''),')',''),CHAR(9),''))))
END

Now use it in SELECT statement
SQL
SELECT OffPhoneNo, dbo.FnPhone(OffPhoneNo) FROM [TableName]
 
Share this answer
 
v3
Comments
rajdeep kumar 16-Feb-12 0:46am    
can u please tell me code, how to do this function?
thatraja 16-Feb-12 0:59am    
Check my updated answer
thatraja 16-Feb-12 2:19am    
What happened? you have accepted my 2 times & rejected 2 times
:confused:
[no name] 16-Feb-12 1:39am    
+5And what if we need to replace the numbers of rows of the table?
thatraja 16-Feb-12 2:02am    
It'll work. Just try that.

BTW you forgot to vote.
Dear Friend,

I think you have to use the functionality of SPLIT function in SQL Server in order to achieve you require.

http://geekswithblogs.net/AngelEyes/archive/2007/04/12/111504.aspx[^]

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648[^]

If this helps you out then mark this as your answer.

Thanks
 
Share this answer
 
v2
Comments
rajdeep kumar 16-Feb-12 0:52am    
no , i don't want to use any function. just tell me in singe select statement? pllllzzzzz

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900