Sometimes you may want to manually trim records so that they
have certain lengths.
The scripts below provide examples on how to best do this.
- --This is the max length you want
- DECLARE @MaxLength INT = 50
-
- --This is the characters you want for an ellipsis.
- --Notice that the default value is the ellipsis character
- --and not three periods. (File systems do not like trailing
periods).
- DECLARE @Ellipsis NVARCHAR(MAX) = '…'
-
- --We do math so that if we ellipsize, we still wont be over
the max length.
- DECLARE @TrimTill INT = @MaxLength - LEN(@Ellipsis)
-
- --Trim Contacts Full Name
- UPDATE
- __M_Contacts
- SET
- Final_FullName
= CONCAT(SUBSTRING(Final_FullName, 1, @TrimTill), @Ellipsis)
- WHERE 1=1
- AND
LEN(Final_FullName) > @MaxLength
-
- --Trim Matter Description
- UPDATE
- __M_Matters
- SET
- Final_Description
= CONCAT(SUBSTRING(Final_Description, 1, @TrimTill), @Ellipsis)
- WHERE 1=1
- AND
LEN(Final_Description) > @MaxLength