Máte koncové mezery
RIGHT poskytne mezery, ale LEN ignoruje koncové mezery
DECLARE @foo varchar(100)
SET @foo = 'abc12345def ' --3 spaces
--right or substring
SELECT RIGHT(@foo, 3)
SELECT SUBSTRING(@foo, LEN(@foo)-2, LEN(@foo))
--demonstrate you get spaces
SELECT REPLACE(RIGHT(@foo, 3), ' ', 'z') --single space
--length differences
SELECT LEN(@foo), DATALENGTH(@foo)
--solution
SELECT RIGHT(RTRIM(@foo), 3)
--or trim your column values before storing
Viz SET ANSI_PADDING
Poznámka:nebudete získat NULL pro vstup bez NULL...
--only NULL if you send in NULL
SELECT RIGHT(NULL, 3)