Skip to content

Instantly share code, notes, and snippets.

@codenamejason
Created January 2, 2018 17:11
Show Gist options
  • Save codenamejason/eab7f3ce239b527ee6ab2230c192713b to your computer and use it in GitHub Desktop.
Save codenamejason/eab7f3ce239b527ee6ab2230c192713b to your computer and use it in GitHub Desktop.
CREATE FUNCTION [dbo].[fnRemoveSpaces](
@string_text VARCHAR(MAX),
@threshold int = 3
)
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @tempText AS VARCHAR(MAX)
SET @tempText = replace(@string_text, char(10), ' ')
SET @tempText = replace(@string_text, char(13), ' ')
WHILE CHARINDEX(SPACE(@threshold),@tempText) > 0
BEGIN
SET @tempText = REPLACE(@tempText, SPACE(@threshold), ' ')
END
RETURN @tempText
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment