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 2000 Forums
 Transact-SQL (2000)
 Replace function

Author  Topic 

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-03-12 : 03:55:40
hello,
how do i use a replace funciton in my SP correctly

I am trying to replace the first 3 characters of every phone number inserted to international format

SELECT REPLACE(phone('080%','080','234') from users)

phone is the column name

thanks
Afrika

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-03-12 : 04:43:22
select replace(phone,'080','234') from table

Madhivanan

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

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-03-12 : 04:51:08
thanks a lot Madhivanan

Afrika
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-03-12 : 04:52:56
However, a very important question

The above code you wrote replaces all occurences with 080. I am particular about the first 3 digits and NOT JUST OCCURENCES of 080


How do i address this ?

Or do i use select replace(phone,'080%','234') from
Afrika
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-03-12 : 05:56:05
Try this

select phone='234'+substring(phone,4,len(phone)) from table where charindex('080',substring(phone,4,len(phone)))>0


Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-03-12 : 06:05:18
Try this

select phone='234'+substring(phone,4,len(phone)) from table where left(phone,3)='080'
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-03-12 : 06:07:52
oh Ok,
i was looking into the case and left functions

But woudl try that as well
Go to Top of Page
   

- Advertisement -