Cleans special characters from string

MSSQL

22. 2. 2023
-- Cleans special charakters from string
CREATE FUNCTION dbo.fn_CleanSpecCharacters
    (
        @Text NVarchar(256)
    )
RETURNS NVarchar(256)
AS
    BEGIN
        DECLARE @intText Int;

        SET @intText = PATINDEX('%[^a-z,0-9,/-]%', @Text);

        WHILE @intText > 0
            BEGIN
                SET @Text = STUFF(@Text, @intText, 1, '');
                SET @intText = PATINDEX('%[^a-z,0-9,/-]%', @Text);
            END;
        RETURN ISNULL(@Text, '');
    END;