views:

32

answers:

1

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.

A: 

There seems to be an undocumented stored procedure that allows you to create your own system objects: sp_ms_marksystemobject

You can read more on http://www.mssqltips.com/tip.asp?tip=1612

KenJ
So close!!! That seems to work great for stored procs, but not for UDFs. Any other suggestions?
mattmc3
that was all I've got. Sorry :)
KenJ