if exists (select * from information_schema.routines where routine_name = 'routineExists' and routine_type = 'function') drop function dbo.routineExists go exec dbo.sp_executesql @statement = N' /* Created: 07.22.2008 by Boyan Kostadinov (boyank@gmail.com) Dependencies: information_schema.routines Parameters: @routineName varchar(255) - The name of the procedure or function @routineType varchar(25) - The type of routine (usually ''procudure'' or ''function'' Usage: select dbo.routineExists(''getCopyInformation'', ''procedure'') select dbo.routineExists(''getCopyInformation'', ''function'') if (select dbo.routineExists(''getCopyInformation'', ''procedure'')) = 1 print ''exists'' Returns: 0 if the routine does not exist 1 if the routine exists Description: Checks the information schema view for the existance of the routine name passed in */ create function dbo.routineExists(@routineName varchar(255), @routineType varchar(25)) returns bit as begin declare @routineExists bit set @routineExists = 0 if exists ( select routine_name from information_schema.routines where routine_name = @routineName and routine_type = @routineType ) set @routineExists = 1 else set @routineExists = 0 return @routineExists end '