Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 parse and update column values

Author  Topic 

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2009-08-06 : 17:06:08
I have a column of data type nvarchar with data of the format 1234-1234. I'd like to remove the dash '-' and update the records accordingly. can anyone gove me a hint?
thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-08-06 : 17:33:08
Use the REPLACE function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2009-08-07 : 08:13:42
thank you. but how do I properly select the values, is there something like regular expression function ?
UPDATE table1
SET column2 = REPLACE(column2,'-','')
WHERE column 2 ??
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-07 : 08:36:33
quote:
Originally posted by KlausEngel

thank you. but how do I properly select the values, is there something like regular expression function ?
UPDATE table1
SET column2 = REPLACE(column2,'-','')
WHERE column 2 ??


What do you mean by properly selected values?

Try

UPDATE table1
SET column2 = REPLACE(column2,'-','')
WHERE column2 like '[0-9][0-9][0-9][0-9][-]%'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2009-08-18 : 01:05:48
Thank you, that's what I needed!

quote:
Originally posted by madhivanan

quote:
Originally posted by KlausEngel

thank you. but how do I properly select the values, is there something like regular expression function ?
UPDATE table1
SET column2 = REPLACE(column2,'-','')
WHERE column 2 ??


What do you mean by properly selected values?

Try

UPDATE table1
SET column2 = REPLACE(column2,'-','')
WHERE column2 like '[0-9][0-9][0-9][0-9][-]%'


Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-18 : 02:21:23
quote:
Originally posted by KlausEngel

Thank you, that's what I needed!

quote:
Originally posted by madhivanan

quote:
Originally posted by KlausEngel

thank you. but how do I properly select the values, is there something like regular expression function ?
UPDATE table1
SET column2 = REPLACE(column2,'-','')
WHERE column 2 ??


What do you mean by properly selected values?

Try

UPDATE table1
SET column2 = REPLACE(column2,'-','')
WHERE column2 like '[0-9][0-9][0-9][0-9][-]%'


Madhivanan

Failing to plan is Planning to fail




You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -