Remove the last character in a string in T-SQL?

前端 未结 21 2312
不思量自难忘°
不思量自难忘° 2020-12-07 09:22

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

For example:

\'TEST STRING\'

to return:

\'TES         


        
相关标签:
21条回答
  • 2020-12-07 10:16

    Try this

    DECLARE @String VARCHAR(100)
    SET @String = 'TEST STRING'
    SELECT LEFT(@String, LEN(@String) - 1) AS MyTrimmedColumn
    
    0 讨论(0)
  • 2020-12-07 10:17

    To update the record by trimming the last N characters of a particular column:

    UPDATE tablename SET columnName = LEFT(columnName , LEN(columnName )-N) where clause
    
    0 讨论(0)
  • 2020-12-07 10:20
    @result = substring(@result, 1, (LEN(@result)-1))
    
    0 讨论(0)
提交回复
热议问题