Created
December 9, 2022 15:42
-
-
Save kwestground/7db6384e42d05123d16ecc425a962f61 to your computer and use it in GitHub Desktop.
Truncate string and count items from comma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR ALTER FUNCTION dbo.func_TruncateWithCount | |
( | |
@input nvarchar(max), @MaxLength int | |
) | |
RETURNS nvarchar(max) | |
AS | |
BEGIN | |
IF (LEN(@input) <= @MaxLength) | |
RETURN @input | |
DECLARE @CountItems int; | |
SET @CountItems = LEN(@input) - LEN(REPLACE(@input, ',', '')) + 1; | |
RETURN SUBSTRING(@input, 1, @MaxLength) + '...('+CAST(@CountItems AS varchar)+')'; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment