Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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.7k 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.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 23, 2019 in SQL by Tech4ever (20.3k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers

500 comments

108k users

Browse Categories

...