/*
功能:取数据库物理文件路径
创建人:baronyang
创建时间:2009-6-29
适用:SQL2005
*/
Alter function Fn_Ex_GetDBPath
(@DBName nvarchar(255),--数据库名
@GetType tinyint=1)--获取类型,1取主文件路径,2取日志文件路径
returns nvarchar(1000)
as
begin
declare @filepath nvarchar(1000)
if @GetType in (1,2)
begin
select @filepath=reverse(physical_name) from sys.master_files where database_id=db_id(@DBName) and file_id=@GetType
set @filepath=right(@filepath,len(@filepath)-charindex('/',@filepath)+1)
set @filepath=reverse(@filepath)
end
return @filepath
end