Technical Article

UDF to strip brackets from phone numbers

,

I find phone numbers to be the messiest data that users enter. There are so many variations with brackets that I wrote this UDF to help clean up the data.

Usage:

SELECT

Firstname

, SURNAME

, udfStripBracket(PHONENUMBER) AS BracketlessNumber

FROM dbo.UserContact

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[udfStripBracket]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[udfStripBracket]
GO

CREATE FUNCTION udfStripBracket  (@str varchar(255))
RETURNS nvarchar(255)
AS
BEGIN
   Declare @udfStripBracket nvarchar(255)
   SELECT @udfStripBracket = Convert(nvarchar(255),REPLACE((SELECT REPLACE(@str,'(','')),')',''))
   RETURN(@udfStripBracket)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating