Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting data characters in a sql statement

Status
Not open for further replies.

msg83

IS-IT--Management
Sep 18, 2002
20
0
0
US
I have a ms sql table called CallPN and in that table there is a column called phone which consist of phone numbers such as 19,9995551212. I need to just take out the 19, but leave the rest. How do I do that. I have a statement to put in the 19, but now i need to delete that 19,. Does anyone have a sql statement that can strip this out. by the way it is a nvarchar column.
 
Code:
Update CallPN
Set    Phone = Right(Phone, Len(Phone) - CharIndex(',', Phone))

This should remove ANYTHING from the phone number field up to (and including) the comma.

If you ALWAYS have [!]19,[/!], then you can simplify this to...

Code:
Update CallPN Set Phone = Replace(Phone, '19,', '')

With this, you are replacing 19, with nothing, which effectively removes it.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top