rod.means
Old Hand
Points: 311
More actions
June 9, 2009 at 1:38 pm
#131737
I was wondering if anyone knows how to pull just the mdf and ldf physical file name from SQL. I know you can pull the entire directory by querying the system tables but I cannot figure out if their is a way to pull just the file name.
Ken Simmons
SSCertifiable
Points: 7822
June 9, 2009 at 1:46 pm
#1007026
Try this...
Select
SUBSTRING(physical_name,LEN(physical_name)- CHARINDEX('\',REVERSE(physical_name))+2 ,LEN(physical_name))
FROM sys.master_files
Lynn Pettis
SSC Guru
Points: 442467
June 9, 2009 at 1:57 pm
#1007034
Or this would work:
select
reverse(left(reverse(physical_name), charindex('\', reverse(physical_name)) - 1)),
*
from
sys.master_files
June 9, 2009 at 1:58 pm
#1007037
Perfect!!!
Thanks Ken
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply