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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help performing an update after a select

Status
Not open for further replies.

Cenedra

Programmer
Jan 2, 2003
114
US
Hi,

I need to write a stored procedure that looks at a phone number field in my database and if the phone number starts with (513) [5-9](6 more digits), I need to update the area code to be (999)-original 7 digits.

For example:

i have a phone number that is (513)566-7788, I need to update it so it is now (999)566-7788.

Can someone assist me in writing this into a stored procedure?

thanks in advance!
 
For example:

CREATE PROCEDURE phone_number
@original_area_code char(3),
@new_area_code char(3)
AS

UPDATE your_table SET
Phone_number = @new_area_code + SUBSTRING( Phone_number, LEN( @original_area_code ) + 1, LEN( Phone_number ) )
WHERE phone_number LIKE ( @original_area_code + '%' )


@original_area and @new_area_code are with brackets, e.g. (513) or (999)

Zhavic

---------------------------------------------------------------
In the 1960s you needed the power of two Comodore64s to get a rocket to the moon. Now you need a machine which is a vast number of times more powerful just to run the most popular GUI.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top