The forum will be down for maintenance over the weekend of August 18-20, 2017. The forum will be shut down on the evening (EDT) of Friday, August 18. Downtime is unknown but may be up to two days. The forum will be restarted as soon as maintenance is complete.

This is how I do it today, but I suspect there are better ways to do it?


declare ls_path nvarchar(200);

set ls_path = 'C:\tempfolder\test\testfile.txt';

    left(ls_path, len(ls_path) -len(row_value) ) cc_path, row_value cc_filename
    sa_split_list(ls_path, '\')
    row_value <> '' and
    line_num = (select max(line_num) from sa_split_list(ls_path, '\') );


asked 18 Jan '16, 11:20

Rolle's gravatar image

accept rate: 0%

I would think it is easier to use locate( ..., '\\', -1 ) to find the last backslash and then split the string at that location.

  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;

Note that backslashes should be doubled ... otherwise sequences like \n will get interpreted as newline (similar for \r and \t and a few others)


permanent link

answered 18 Jan '16, 11:44

Mark%20Culp's gravatar image

Mark Culp
accept rate: 40%

edited 18 Jan '16, 11:49

Wow, was just about to post something comparable but had to lookup the third LOCATE() parameter, as usual:)

(18 Jan '16, 11:46) Volker Barth
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 18 Jan '16, 11:20

question was seen: 298 times

last updated: 18 Jan '16, 11:49