IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_TestObjectsGet]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[sp_TestObjectsGet] 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_TestObjectsGet]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[sp_TestObjectsGet] AS' END GO ALTER PROCEDURE [dbo].[sp_TestObjectsGet] @TestObjectName nvarchar(50) = null ,@TemplateName nvarchar(50) = null ,@SysBuilt bit = null AS BEGIN SET NOCOUNT ON; declare @TemplateId int declare @TestObjectId int set @TemplateId = dbo.foo_IdGetTemplate(@TemplateName) set @TestObjectId = dbo.foo_IdGetTestObject(@TestObjectName) SELECT [TestObjectName] ,tob.[LastModifiedBy] ,tob.[LastModified] ,tt.[TemplateName] ,tob.[LocalOnly] ,tob.[ParentObject] ,tob.[SysBuilt] ,tob.[OrigSerialNumber] ,tob.[OrigTemplate] ,tob.[Embedded] FROM [dbo].[TestObjects] tob inner join [dbo].[TestObjectTemplates] tt on tt.TemplateId = tob.TemplateId where (@TestObjectName is null or tob.TestObjectId = @TestObjectId) and (@TemplateName is null or tt.TemplateId = @TemplateId) and (@SysBuilt is null or tob.SysBuilt = @SysBuilt) END GO