IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_TestObjectExist]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[sp_TestObjectExist] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_TestObjectExist]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[sp_TestObjectExist] AS' END GO ALTER PROCEDURE [dbo].[sp_TestObjectExist] @TestSetupName nvarchar(50) = null ,@TestObjectName nvarchar(50) = null ,@rv int = 0 output AS BEGIN declare @TestObjectId int declare @TestSetupId int set @TestObjectId = dbo.foo_IdGetTestObject(@TestObjectName) set @TestSetupId = dbo.foo_IdGetTestSetup(@TestSetupName) set @rv = 0 if(exists(select tobj.TestObjectName from TestSetupObjects tso inner join TestObjects tobj on tobj.TestObjectId = tso.TestObjectId where tso.TestSetupId =@TestSetupId and tobj.TestObjectId = @TestObjectId)) begin set @rv = 1 end END GO