IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[fn_diagramobjects]') AND type = 'FN')
DROP FUNCTION [dbo].[fn_diagramobjects]
GO


CREATE FUNCTION dbo.fn_diagramobjects() 
RETURNS int
WITH EXECUTE AS N'dbo'
AS
BEGIN
declare @id_upgraddiagramsint
declare @id_sysdiagramsint
declare @id_helpdiagramsint
declare @id_helpdiagramdefinitionint
declare @id_creatediagramint
declare @id_renamediagramint
declare @id_alterdiagram int 
declare @id_dropdiagramint
declare @InstalledObjectsint

select @InstalledObjects = 0

select @id_upgraddiagrams = object_id(N'dbo.sp_upgraddiagrams'),
@id_sysdiagrams = object_id(N'dbo.sysdiagrams'),
@id_helpdiagrams = object_id(N'dbo.sp_helpdiagrams'),
@id_helpdiagramdefinition = object_id(N'dbo.sp_helpdiagramdefinition'),
@id_creatediagram = object_id(N'dbo.sp_creatediagram'),
@id_renamediagram = object_id(N'dbo.sp_renamediagram'),
@id_alterdiagram = object_id(N'dbo.sp_alterdiagram'), 
@id_dropdiagram = object_id(N'dbo.sp_dropdiagram')

if @id_upgraddiagrams is not null
select @InstalledObjects = @InstalledObjects + 1
if @id_sysdiagrams is not null
select @InstalledObjects = @InstalledObjects + 2
if @id_helpdiagrams is not null
select @InstalledObjects = @InstalledObjects + 4
if @id_helpdiagramdefinition is not null
select @InstalledObjects = @InstalledObjects + 8
if @id_creatediagram is not null
select @InstalledObjects = @InstalledObjects + 16
if @id_renamediagram is not null
select @InstalledObjects = @InstalledObjects + 32
if @id_alterdiagram  is not null
select @InstalledObjects = @InstalledObjects + 64
if @id_dropdiagram is not null
select @InstalledObjects = @InstalledObjects + 128

return @InstalledObjects 
END