first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

T-SQL Code: A Function for Checking for the Existence of an Object; fItemExists()

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

mod date: 2007-04-04T19:44:27.000Z