Just an alternative:
select SUBSTRING('1112223344',1,3)+'-'+
SUBSTRING('1112223344',4,3)+'-'+
SUBSTRING('1112223344',7,2)+'-'+
SUBSTRING('1112223344',9,2)
In your case:
CREATE PROCEDURE SP_TELEPHONE_NUMBER
(@TELEPHONE_NUMBER VARCHAR(4000))
AS
BEGIN
INSERT INTO DOSYA_ARSIV(TELEPHONE_NUMBER)
VALUES
(
SUBSTRING(@TELEPHONE_NUMBER,1,3)+'-'+
SUBSTRING(@TELEPHONE_NUMBER,4,3)+'-'+
SUBSTRING(@TELEPHONE_NUMBER,7,2)+'-'+
SUBSTRING(@TELEPHONE_NUMBER,9,2)
)
END
As noobob has mentioned in his comment, you may have this as an INT type (INT,BIGINT or something similar) and just handle the way it is displayed in the front end. For instance in C# you would have it as:
TELEPHONE_NUMBER.ToString("###-###-##-##");
Another comment would be that defining the expected argument as VARCHAR(4000)
is way too much. Though it might not be very bad, it is a good point to define arguments or variables as close to expected input as you can. In your case i would say that something like VARCHAR(30)
would be enough.