Introduction
In some of cases we need remove last character of string.In this snippet, we will see how to get and remove last character in string.
Sample string: 'DotNetMirror,'
Now we will get last character comma(,) from the string.
Get Last Char in string:
Declare @SampleString varchar(100)
set @SampleString ='DotNetMirror,'
select RIGHT(@SampleString , 1) --output: DotNetMirror
Remove the last char(comma) in string :
IF(LEN(@String)> 0 AND RIGHT(@String, 1) = ',')
BEGIN
select substring(@String, 1, (len(@String) - 1)) --or
SET @String = LEFT(@String, LEN(@String) - 1)
END
select @String