RSS Forums RSS
Please support our MS SQL advertiser: Programming Forums

need help on replacing a value in a field (MSSQL)

Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,166
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 59
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: need help on replacing a value in a field (MSSQL)

  #2  
Apr 3rd, 2007
update <tablename> set MobileNo = replace(MobileNo, '-', '') 

You don't mention the name of the table so replace <tablename> with the name of your table (minus the chevrons obviously)

I ALWAYS backup my database before these kind of large update operations. In this simple case instead of a full backup you could add a new column to the table first, call it MobileNo_OLD or something, give it the same datatype as MobileNo and then first do:

Update <tablename> set MobileNo_OLD = MobileNo 

Now you can always undo your update if you stuff it up, or someone (they always do) changes their mind.

Another tip is to do:

SELECT top 100 replace(MobileNo, '-', '') as [New MobileNo] from <tablename> 

To see what the result of your update will look like before you actually commit to an update statement. (I put the 'top 100' in coz I dunno how massive your table might be in number of records, if you have only few hundred you can take that out) Yes you do you said it has 400 numbers! I'm so slow sometimes!
Last edited by hollystyles : Apr 3rd, 2007 at 7:47 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:32 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC