Hi All,
I am trying to replace only first 3-digit of phone number starting with 011 to 000.
CREATETABLE #temp(stringRep VARCHAR(60))
INSERTINTO #temp(stringRep)VALUES('011-203-0011')
INSERTINTO #temp(stringRep)VALUES('011-203-2333')
DECLARE @.startPos INT
SET @.startPos = 1
UPDATE #temp SET stringRep =REPLACE(stringRep,SUBSTRING(stringRep, 1,
3),'000')
SELECT*FROM #temp
DROPTABLE #temp
stringRep
000-203-0000
000-203-2333
it also replaces the last three digit with 000. the result i would like to get is
stringRep
000-203-0011
000-203-2333
can anybody advise me on this? thanks!
Try:
update #temp
set stringRep = stuff(stringRep, 1, 3, '000')
where stringRep like '011%'
AMB
sql
No comments:
Post a Comment