Function to Make Email Address Compatible in SQL Server
Hello everyone,
In this article, I will try to give information about the function that makes the e-mail address compatible in SQL Server.
In SQL Server, in some cases, Turkish characters may be entered in the e-mail addresses or it may be necessary to correct the e-mail addresses before entering the e-mail addresses.
You can easily do this using the function below.
CREATE FUNCTION dbo.EPosta_Adresi_Duzelt (@EMAIL NVARCHAR(200))
RETURNS NVARCHAR(200)
AS
BEGIN
DECLARE @TempString NVARCHAR(200)
SET @TempString = @EMAIL
IF NULLIF(@TempString, '') IS NOT NULL
BEGIN
IF @TempString LIKE '%@%'
BEGIN
SET @TempString = REPLACE(@TempString, ' ', '')
SET @TempString = REPLACE(@TempString, 'Ü', 'u')
SET @TempString = REPLACE(@TempString, 'ü', 'u')
SET @TempString = REPLACE(@TempString, 'Ğ', 'g')
SET @TempString = REPLACE(@TempString, 'ğ', 'g')
SET @TempString = REPLACE(@TempString, 'Ç', 'c')
SET @TempString = REPLACE(@TempString, 'ç', 'c')
SET @TempString = REPLACE(@TempString, 'Ş', 's')
SET @TempString = REPLACE(@TempString, 'ş', 's')
SET @TempString = REPLACE(@TempString, 'İ', 'i')
SET @TempString = REPLACE(@TempString, 'I', 'i')
SET @TempString = REPLACE(@TempString, 'ı', 'i')
SET @TempString = REPLACE(@TempString, 'Ö', 'o')
SET @TempString = REPLACE(@TempString, 'ö', 'o')
SET @TempString = LOWER(@TempString)
END
ELSE
BEGIN
SET @TempString = 'Geçersiz E-Mail Adresi';
END
END
ELSE
BEGIN
SET @TempString = 'Boş E-Mail Adresi';
END
RETURN @TempString
END
GO
--Using the Function
SELECT
dbo.EPosta_Adresi_Duzelt('Sqlservereğitimleri@sqlservereğitimleri.com')
When you create and run the above function, you will see a result similar to the one below.
As you can see, we have made the e-mail address compatible.
Good luck to everyone in business and life.