TSQL RIGHT 字符串函数不起作用

2021-09-10 00:00:00 tsql sql-server varchar

我无法理解为什么 RIGHT 函数对我不起作用.我试图在此处放入尽可能多的输出,如果阅读起来令人困惑,我深表歉意.

I am having trouble understanding why the RIGHT function is not working for me. I tried to fit as much output in here, my apologies if it is confusing to read.

DECLARE @Nbr VARCHAR(27)

SELECT @Nbr = xmz.nbr
FROM @xml_temp AS xmz

SELECT @Nbr AS 'Number', 
       LEFT(@Nbr, 4) AS 'LEFT', 
       LEN(@Nbr) AS 'Length', 
       SUBSTRING(@Nbr, 10, 4) AS 'SUBSTRING', 
       RIGHT(@Nbr, 4) AS 'RIGHT'

号码:154448887859999
左:1544
长度:15
子字符串:9999
右图:空

Number: 154448887859999
LEFT: 1544
Length: 15
SUBSTRING: 9999
RIGHT: EMPTY

推荐答案

可能有空格,LEN 不计算空格而 DATALENGTH 计算

spaces perhaps, LEN doesn't count spaces while DATALENGTH does

你能跑吗

SELECT DATALENGTH(@Nbr) AS 'Length',
 RIGHT(RTRIM(@Nbr), 4) AS 'RIGHT'

相关文章