Using SQL Server 2008, I'd like to create a UDF that gives me the create date of an object. This is the code:
create function dbo.GetObjCreateDate(@objName sysname) returns datetime as
begin
declare @result datetime
select @result = create_date from sys.objects where name = @objname
return @result
end
go
I'd like to put this UDF in the master database so that it is accessible from anywhere, except that if I do that then the sys.objects
reference pulls from the master
database instead of the database that I'm initiating my query from. I know you can do this as the information_schema
views sit in master
and just wrap calls to local instances of sys.objects, so I'm hoping there's a simple way to do that with my UDF as well.