query help- list path (not filename) for all datfiles

  • working a query to list all paths which contain data or log files. starting with something like:

    select physical_name from master.sys.master_files

    but want to only include the path, not the file name, and only list each path once...

    so, everything left of the rightmost "\" should exclude filenames, and maybe a distinct in there...

    but cant figure out how to say "everything left of the rightmost \"

    any help would be appreciated.

  • as often happens, I figure it out shortly after posting:

    select distinct (LEFT(physical_name, (LEN(physical_name)-(CHARINDEX('\', REVERSE(physical_name)) - 1)))) as path

    FROM master.sys.master_files

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply