Takeshi Tawarada
Takeshi Tawarada

Reputation: 113

SQL - remove last character(s)

I'm trying to remove the last character of a string if it is a '/' and the string could have multiple '/'s on the end.

For example, I have:

And want to get:

Upvotes: 0

Views: 180

Answers (4)

Cee
Cee

Reputation: 11

Try something like this:

` SELECT REVERSE(SUBSTRING(reverse('c/string2//'),
PATINDEX('%[^/ ]%',reverse('c/string2//')),
DATALENGTH(reverse('c/string2//'))))`

reference: http://raresql.com/2013/05/20/sql-server-trim-how-to-remove-leading-and-trailing-charactersspaces-from-string/

Upvotes: 0

fhueser
fhueser

Reputation: 649

You can simply use:

SET @STR = 'b/bla///';
SELECT TRIM(TRAILING '/' FROM @STR);

Upvotes: 1

ImCrimson
ImCrimson

Reputation: 146

Use the Replace() function HERE EX

replace(string1, '/','') 

it will remove all of those '/' signs

Upvotes: 1

ragerory
ragerory

Reputation: 1378

REPLACE is what you're looking for.

SELECT REPLACE(col1, '/', '') FROM...

You can read more here

Upvotes: 1

Related Questions