I have the following string: \'BOB*\', how do I trim the * so it shows up as \'BOB\'
I tried the RTRIM(\'BOB*\',\'*\') but does not work as says needs only 1 paramet
CREATE FUNCTION dbo.TrimCharacter
(
@Value NVARCHAR(4000),
@CharacterToTrim NVARCHAR(1)
)
RETURNS NVARCHAR(4000)
AS
BEGIN
SET @Value = LTRIM(RTRIM(@Value))
SET @Value = REVERSE(SUBSTRING(@Value, PATINDEX('%[^'+@CharacterToTrim+']%', @Value), LEN(@Value)))
SET @Value = REVERSE(SUBSTRING(@Value, PATINDEX('%[^'+@CharacterToTrim+']%', @Value), LEN(@Value)))
RETURN @Value
END
GO
--- Example
----- SELECT dbo.TrimCharacter('***BOB*********', '*')
----- returns 'BOB'