1

I have a variable which is a VARCHAR and will contain a list of folders (1 or more). It may looks like that :

@Folder = '/folder1/folder2/'
or
@Folder = 'folder1/folder2/'
or
@Folder = '/Folder1/Folder2'

And if the first and the last characater of my string are '/', i want to remove them and my variable should be always

@Folder = 'Folder1/Folder2'

Thanks for your help

asked Mar 19, 2019 at 15:34

1 Answer 1

3

You could use the LEFT() and RIGHT() functions to do this.

DECLARE @Folder varchar(20) = '/folder1/folder2/';
IF LEFT(@folder,1) = '/' 
SET @Folder = RIGHT(@Folder ,LEN(@Folder)-1);
IF RIGHT(@folder,1) = '/' 
SET @Folder = LEFT(@Folder ,LEN(@Folder)-1);
SELECT @Folder;

Result

(No column name)
folder1/folder2
answered Mar 19, 2019 at 15:39
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.