Telephone's code replacement

Hi everyone))) Can anybody help me with the SQL task?

We have: telephone’s data type is decimal
Task: Need to replace telephone code from 495 to 499.


UPDATE dbo.Readers
SET Contact_telephone = REPLACE(Contact_telephone, 495, 499);

If I do it like this, every single 495 record in Readers.Contact_telephone will be replaced with 499. This isn’t right :cry:

I’ll be very glad if you help me)))

Solved by me)))

If somebody will get into this trouble, so here’s the solution:

UPDATE dbo.Readers_new

--using STUFF to replace Contact_telephone's value on 499 with len = 3 starting from 2nd index
SET Contact_telephone = STUFF(Contact_telephone, 2, 3, 499) 

--where Contact_telephone's value = 495 starting from 2nd index with len = 3
WHERE SUBSTRING(STR(Contact_telephone , 11), 2, 3) = 495

--select everything from Readers_new table
SELECT * FROM dbo.Readers_new

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.