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

前端 未结 21 2376
不思量自难忘°
不思量自难忘° 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 09:58

    you can create function

    CREATE FUNCTION [dbo].[TRUNCRIGHT] (@string NVARCHAR(max), @len int = 1)
    RETURNS NVARCHAR(max)
    AS
    BEGIN
        IF LEN(@string)<@len
            RETURN ''
        RETURN LEFT(@string, LEN(@string) - @len)
    END
    

提交回复
热议问题