0 votes
1 view
in SQL by (20.3k points)

How do I remove the last character in a string in T-SQL?

For example:

'TEST STRING'

to return:

'TEST STRIN'

1 Answer

0 votes
by (40.3k points)

Try the below code:

DECLARE @String VARCHAR(100)

SET @String = 'TEST STRING'

-- Chop off the end character

SET @String = 

     CASE @String WHEN null THEN null 

     ELSE (

         CASE LEN(@String) WHEN 0 THEN @String 

            ELSE LEFT(@String, LEN(@String) - 1) 

         END 

     ) END

SELECT @String

Related questions

0 votes
1 answer
asked Sep 10, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...