Arrange the phone number for U.S

Posted by VIJI Monday, June 29, 2009

About FuncPhone SQL User defined Function

/* This function takes a phone number, and checks if it is a number for the. */
/* US. If it is then it puts the number in the form 999-999-9999 or */
/* 999-9999 depending on whether or not it is a 10 or 7 digit number */
/* It will also drop any 0 if there are any. */

CREATE FUNCTION dbo.FuncPhone(@String varchar(2000),@Country as varchar(50)) RETURNS varchar(50)
AS


BEGIN

Declare @Phone as varChar(50)

If @Country = 'US' Begin
Set @Phone = dsw.dbo.boaStrip(@String,'() -')
if len(@Phone) = 10
Set @Phone = substring(@Phone,1,3) +'-' + substring(@Phone,4,3) + '-' + substring(@Phone,7,4)
Else Begin
if len(@phone) = 7
Set @Phone =substring(@String,1,3) + '-' + Substring(@String,4,4)
End
End

Return(@Phone)

END

USAGE

/* Example: boaPhone('09999999999, 'US') = 999-999-9999 */

0 Responses to Arrange the phone number for U.S

Post a Comment