http://www.sqlservercentral.com/blogs/sqlstudies/2012/10/19/fn_object_type/

Printed 2014/04/17 04:54PM

fn_OBJECT_TYPE

By Kenneth Fisher, 2012/10/19

I recently started using OBJECT_NAME, OBJECT_SCHEMA_NAME and OBJECT_ID functions; unfortunately I really could have used OBJECT_TYPE but it doesn’t exist (yet?). So for now I wrote one of my own.

FYI I originally wrote it as sp_ and created it in the master db thinking that this would cause it to be available from any database. Unfortunately it appears that this doesn’t work for functions, only stored procedures, views and would you believe tables? I’d love it if someone would explain that one to me sometime.

CREATE FUNCTION dbo.fn_OBJECT_TYPE (@Object_Id INT) 
RETURNS nvarchar
AS
BEGIN
DECLARE @type_desc nvarchar(120)

SELECT @type_desc = type_desc
FROM sys.all_objects
WHERE object_id = @Object_Id

RETURN @type_desc
END
GO



Copyright © 2002-2014 Simple Talk Publishing. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.