on 2016 Jan 18 11:20 AM
This is how I do it today, but I suspect there are better ways to do it?
BEGIN
declare ls_path nvarchar(200);
set ls_path = 'C:\\tempfolder\\test\\testfile.txt';
select
left(ls_path, len(ls_path) -len(row_value) ) cc_path, row_value cc_filename
from
sa_split_list(ls_path, '\\')
where
row_value <> '' and
line_num = (select max(line_num) from sa_split_list(ls_path, '\\') );
END
I would think it is easier to use locate( ..., '\\\\', -1 ) to find the last backslash and then split the string at that location.
begin
declare @path varchar(255) = 'c:\\\\my\\\\path\\\\name\\\\filename.jpg';
select locate( @path, '\\\\', -1 ) as len,
left( @path, len-1 ) as path,
substr( @path, len+1 ) as filename;
end;
Note that backslashes should be doubled ... otherwise sequences like \\n will get interpreted as newline (similar for \\r and \\t and a few others)
HTH
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
9 | |
9 | |
8 | |
8 | |
7 | |
7 | |
6 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.