Created
July 6, 2016 18:55
-
-
Save kevindb/ec61ae3c8b481ef1a1a5481448216af6 to your computer and use it in GitHub Desktop.
SQL Server function to truncate a string and add an ellipsis
This file contains hidden or 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 FUNCTION [dbo].[f_truncateWithEllipsis] | |
( | |
@value VARCHAR(8000), | |
@maxLength INT | |
) | |
RETURNS VARCHAR(8000) | |
AS | |
BEGIN | |
SET @value = LTRIM(RTRIM(@value)); | |
RETURN CASE WHEN LEN(@value) > @maxLength | |
THEN LEFT(@value, @maxLength - 1) + '…' | |
ELSE @value | |
END | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment