Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Drop Procedure If It Exists
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

gregoryagu
Yak Posting Veteran

80 Posts

Posted - 07/31/2008 :  17:21:57  Show Profile  Reply with Quote
--Drops a Procedure if it exists and prints a message with the result.
CREATE PROCEDURE [dbo].[Utils_DropProcedure]
(
@ProcedureName varchar(128)
)
AS
BEGIN
Declare @SQL varchar(4000)
set @SQL = 'IF (EXISTS (SELECT * FROM dbo.sysobjects '
+ ' WHERE id = OBJECT_ID('''
+ @ProcedureName + ''') AND OBJECTPROPERTY(id,''IsProcedure'') = 1))'
+ 'BEGIN PRINT ''Dropping the Procedure:'' PRINT '''
+ @ProcedureName + ''' DROP PROCEDURE ['
+ @ProcedureName + '] END ELSE BEGIN PRINT ''Procedure Not Found:'''
+ 'Print ''' + @ProcedureName + ''' END'


EXECUTE (@SQL)
END

GO
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000