What will be the output of this query?

DECLARE @str  NVARCHAR(10)
SET @str = '1, 2, 3, '
SET @str = LEFT(@str, LEN(@str)- 2)
SELECT @str

Answer: '1, 2, ' (space after comma)
Explanation: The LEN function in SQL removes the trailing spaces when calculating the length of the string. Therefore the LEN returns a 8 and -2 is 6, so only the first 6 characters are returned.

原文地址:https://www.cnblogs.com/buhaiqing/p/1565036.html