Hey everyone,
sorry, i am trying to get the actual file name accurately from the path, what i currently have is:
E:\Backup\Server1\Database1\Database1_131983519013.bak
and want to get just:
Database1_131983519013.bak
trying to use trim or left etc. but finding it difficult as some other database names might be longer or shorter, so its random, any idea how I can get just the name?
thanks in advance
This perhaps?
DECLARE @MyString varchar(255)='E:\Backup\Server1\Database1\Database1_131983519013.bak'
SELECT RIGHT(@MyString, CHARINDEX('\', REVERSE(@MyString)) - 1)
February 14, 2021 at 12:07 pm
If you know the folder path in advance, you can simply remove it to get the file name:
DECLARE @BackupFilePath VARCHAR(300) = 'E:\Backup\Server1\Database1\Database1_131983519013.bak';
SELECT
@BackupFilePath
, FileName = REPLACE(@BackupFilePath, 'E:\Backup\Server1\Database1\', '');
February 16, 2021 at 11:09 pm
Thank you sir, worked perfectly
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy