I have a string of type VARCHAR(128) in MS SQL Server, which has this value: 'abc '.
However, these trailing "spaces" are not regular spaces (ASCII 32), they are of ASCII 0. I want to trim these trailing "spaces", but I could not get it to work.
I have tried the following approaches:
ltrim and rtrim
replace('abc ', CHAR(0), '') substring('abc ', 0, charindex(CHAR(0), 'abc ')) But none of these seem to work as intended.
How can I remove these trailing ASCII 0 characters from the string?
REPLACEshould work according to this script:DECLARE @a varchar(10) = CAST(0x616200 AS varchar(10)); SELECT DATALENGTH(@a) AS before, DATALENGTH(REPLACE(@a, CHAR(0), '')) AS after;