USE [Database] GO IF OBJECT_ID('fItemExists') IS NOT NULL BEGIN DROP FUNCTION fItemExists IF OBJECT_ID('fItemExists') IS NOT NULL PRINT '<<< FAILED DROPPING FUNCTION fItemExists >>>' ELSE PRINT '<<< DROPPED FUNCTION fItemExists >>>' END GO CREATE FUNCTION dbo.fItemExists ( @objectName nvarchar(128) = NULL , @propertyName nvarchar(128) = NULL ) RETURNS bit AS BEGIN DECLARE @bit bit SET @bit = 0 IF EXISTS( SELECT [object] = o.name , [property] = p.name FROM sysObjects o , sysColumns p WHERE o.id = p.id AND o.name = @objectName AND p.name = @propertyName ) BEGIN SET @bit = 1 END
RETURN @bit END GO GRANT EXECUTE ON fItemExists TO public GO IF OBJECT_ID('fItemExists') IS NOT NULL PRINT '<<< CREATED FUNCTION fItemExists >>>' ELSE PRINT '<<< FAILED CREATING FUNCTION fItemExists >>>' GO