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
 Removing two dashes in a field

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-03-10 : 09:51:25
I have a customer number and would like to remove the -(dashes) in the record.

The field is called F1

Here's a row of data
2569-6589-22

How do I do this in sql 2005?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-10 : 09:54:39
Select replace(F1,'-','') from your_table

Madhivanan

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

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-10 : 09:54:55
quote:
Originally posted by JJ297

I have a customer number and would like to remove the -(dashes) in the record.

The field is called F1

Here's a row of data
2569-6589-22

How do I do this in sql 2005?



Could you please check
SELECT '2569-6589-22'

SELECT REPLACE('2569-6589-22','-','')
Go to Top of Page

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-10 : 10:03:01
Oh!.my god..Just 16 sec Mr.Madhi..Any how i Can't Beat you..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-10 : 10:05:11
quote:
Originally posted by haroon2k9

Oh!.my god..Just 16 sec Mr.Madhi..Any how i Can't Beat you..



You need to type fast

Madhivanan

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

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-10 : 10:07:05
quote:
Originally posted by madhivanan

quote:
Originally posted by haroon2k9

Oh!.my god..Just 16 sec Mr.Madhi..Any how i Can't Beat you..



You need to type fast

Madhivanan

Failing to plan is Planning to fail



Lol!!!!
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-03-10 : 10:11:17
Thanks that worked but I have other fields in the table how do I just replace that field F1 and not wipe out the others, F2, F3, and F4?

Don't worry this was a test table.
Go to Top of Page

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-10 : 10:13:01
quote:
Originally posted by JJ297

Thanks that worked but I have other fields in the table how do I just replace that field F1 and not wipe out the others, F2, F3, and F4?

Don't worry this was a test table.



Sorry i wasn't getting you
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-03-10 : 10:15:30
When I ran this:
Select replace(F1,'-','') from your_table

it worked but I just had the one column on the screen. When I opened the table it didn't make any changes. So I see it makes a new column that's fine but how do I put that into my same table?
Go to Top of Page

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-10 : 10:19:15
quote:
Originally posted by JJ297

When I ran this:
Select replace(F1,'-','') from your_table

it worked but I just had the one column on the screen. When I opened the table it didn't make any changes. So I see it makes a new column that's fine but how do I put that into my same table?



Do you mean by Updating the Original Table.
Just Update

Update t
set col=replace(F1,'-','')
from tbl t
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-03-10 : 10:25:59
Yes that's it!!! Thanks so much. So happy you guys are racing one another to answer our questions. This way we don't wait too long for an answer!
Go to Top of Page

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-10 : 10:30:06
quote:
Originally posted by JJ297

Yes that's it!!! Thanks so much. So happy you guys are racing one another to answer our questions. This way we don't wait too long for an answer!



you are please welcome
Go to Top of Page
   

- Advertisement -