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

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2006
Posts: 21
Reputation: newMeg is an unknown quantity at this point 
Solved Threads: 0
newMeg newMeg is offline Offline
Newbie Poster

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

 
0
  #1
Apr 3rd, 2007
Hi,

I have a table in which there is a field for mobile no. Currently the data in the field has been entered with a dash(-) after the code.

eg-

MobileNo (this is the field name)
-------------------------------------
1. 6016-2880537
2. 6012-3137200

so there is about 400 records in the table now. How possible is it for me to replace the delimeter (-) with '' or to remove the dash from the column mobileno with a single query. I know i can go remove the dash manually in enterprise manager,but it's time consuming.

Pls help..any help is greatly appreciated.

Thanks in advanced.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

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

 
0
  #2
Apr 3rd, 2007
  1. 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:

  1. 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:

  1. 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 Quick reply to this message  
Join Date: Jul 2006
Posts: 21
Reputation: newMeg is an unknown quantity at this point 
Solved Threads: 0
newMeg newMeg is offline Offline
Newbie Poster

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

 
0
  #3
Apr 11th, 2007
Hi hollystyles ,

you are always a great help. sorry for the late reply.the query example u said works great and solved my problem.

thanks again and sorry for th elate response.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

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

 
0
  #4
Apr 11th, 2007
Hey no problem glad I could help.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1
Reputation: Josware is an unknown quantity at this point 
Solved Threads: 0
Josware Josware is offline Offline
Newbie Poster

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

 
0
  #5
Aug 4th, 2009
Hey Hollystyles ¡Thx! You Rocks!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC