How to Clean unwanted symbols in a Number column In SQL server ?
. How to clean a phone Number In SQL Server ?
I have a table like this. In this table i want to display phone number without (.) symbol. for this we suppose to create a function.
Table info:
CREATE A USER DEFINED FUNCTION:- USE BELLOW CODE TO CREATE A FUNCTION IN SQL SERVER(SSMS)
create function Udf_getNumber ( @String Nvarchar(200))
Returns nvarchar(200)
As
Begin
Declare @intalpha int
set @intalpha = PATINDEX('%[^0-9]%',@String)
Begin
while @intalpha >0
Begin
set @String =STUFF(@String,@intalpha,1,'')
set @intalpha =PATINDEX('%[^0-9]%',@String)
end
end
Return isnull(@String,0)
end
once create the function use this function to get desired output
note:- use function Fully Qualified name (schema name. function name eg dbo.Udf_getNumber)
Query to get data:-
select EMPLOYEE_ID,FIRST_NAME,PHONE_NUMBER , dbo.Udf_getNumber(PHONE_NUMBER) as Phonenumber
from CustmerInfo
Output:-
This function also help you to clean all type of data.
Comments