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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Does stored procedure exists???

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-09-14 : 09:48:50
Louis writes "Is it possibble to write a SQL statement that returns "True" or "False" if a stored procedure exists. Basically write a SQL statement that checks whether or not the Stored Procedure exist in the database???


Thanks in advance"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-14 : 09:53:10
many ways to do it:

1)
IF EXISTS (SELECT name 
FROM sysobjects
WHERE name = N'proc1'
AND type = 'P')

2)
If Exists (Select * 
from Information_schema.Routines
Where Routine_Name = 'Proc1'


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-14 : 09:53:11
If exists*Select * from sysobjects where xtype='p' and name='Procedure name')
Print 'True'
else
Print 'False'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-14 : 09:54:01


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -