Prev: Question about MS newsgroups posting
Next: How to specify ranges with batches while updating a column?
From: Greg Berthume on 16 Feb 2010 21:41 I can't remember how I did this before and not having much success with my syntax. I just want to do a simple search and replace of all dashes in a field with a blank. Table = Vendor Column = PhoneNumber Basically: replace(PhoneNumber,'-','') I just want to strip the - (dash) from the field. What's the easiest way to do this? SQL Server 2005. Thanks, Greg
From: Plamen Ratchev on 16 Feb 2010 21:56 You posted the correct syntax: SELECT REPLACE(PhoneNumber, '-', '') AS phone FROM Vendor; Or if you need to update: UPDATE Vendor SET PhoneNumber = REPLACE(PhoneNumber, '-', '') WHERE PhoneNumber LIKE '%-%'; -- Plamen Ratchev http://www.SQLStudio.com
From: Greg Berthume on 16 Feb 2010 22:01
Perfect. Thanks Plamen! It's been one of those brain dead evenings. LOL "Plamen Ratchev" <Plamen(a)SQLStudio.com> wrote in message news:SYSdna08ULl5x-bWnZ2dnUVZ_jVi4p2d(a)speakeasy.net... > You posted the correct syntax: > > SELECT REPLACE(PhoneNumber, '-', '') AS phone > FROM Vendor; > > Or if you need to update: > > UPDATE Vendor > SET PhoneNumber = REPLACE(PhoneNumber, '-', '') > WHERE PhoneNumber LIKE '%-%'; > > -- > Plamen Ratchev > http://www.SQLStudio.com |