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

quick charindex question

Status
Not open for further replies.

DanC

Programmer
Jan 12, 2001
65
US
I have a phone number field that is varchar(50) that includes extensions. The extensions are designated by an 'x' as in 703 987-9878 x5543. The extension length varies. I can pull the extension part out into another column using:
select right(wphone,len(wphone)-charindex('x',wphone)) from mytable where wphone like '%x%'

My question is how do I remove the extension part from the original field? Or pull the other side of the wphone field into a new column? I've tried a couple different ways, but can't get it quite right.

Thanks
-D
 
select left(wphone,charindex('x',wphone)-1) as shortphone
from mytable where wphone like '%x%'
 
thanks alot, it worked perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top