Hi McDonald,
This may not be the correct way of doing it. But you can try it.
If we believe that wherever the data and log files are stored for MASTER database in SQL Server as DEFAULT PATH for databases, then you can use this.
SYSDATABASES has filenames, database names etc..
--gives the database name,data filename for all databases
select name,filename from sysdatabases
--database name, filepath for master database
select name,filename from sysdatabases where name='master'
--(1)
--this is to get the path of master data file
select reverse(substring(reverse(filename),charindex('\',reverse(filename),1),len(filename)))
from sysdatabases where name='master'
to get the path from filename, u can make good logic to extract the required path.
--there you go
--i got one more idea to extract it simply
--because we know the datafile name for MASTER
--(2)
select replace(filename,'MASTER.MDF','') from sysdatabases where name='master'
Statements (1) and (2) will give the same result.
But I am not sure whether is correct to extract the DEFAULT PATH from sysdatabases.
Need to look more in BOL...
Hope this helps.
Sreenivas
avnsr@hotmail.com