Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSQL RIGHT String function not working

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'

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

like image 569
Jaiesh_bhai Avatar asked Feb 16 '23 01:02

Jaiesh_bhai


1 Answers

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

can you run

SELECT DATALENGTH(@Nbr) AS 'Length',
 RIGHT(RTRIM(@Nbr), 4) AS 'RIGHT'
like image 74
SQLMenace Avatar answered Mar 20 '23 10:03

SQLMenace