ALTER PROCEDURE [dbo].[sp_TestSetupObjectsUpdateInsert] @TestSetupId int = 0 ,@TestSetupName nvarchar(255) = null ,@TestObjectId int = 0 ,@TestObjectName nvarchar(255) = null ,@TargetSampleRate float ,@ExcitationWarmupTimeMS int ,@LocalOnly bit ,@TestObjectType nvarchar(50) ,@TestObjectPosition nvarchar(50) ,@DisplayOrder int ,@new_id int output ,@errorNumber int output ,@errorMessage nvarchar(250) output AS BEGIN set @errorNumber = 0; set @errorMessage = space(0); set @new_id = 0; if (@TestSetupId =0) begin set @TestSetupId = dbo.foo_IdGetTestSetup(@TestSetupName) end if(@TestObjectId =0) begin set @TestObjectId = dbo.foo_IdGetTestObject(@TestObjectName) end if(exists(select * from [dbo].[TestSetupObjects] where TestSetupId = @TestSetupId and TestObjectId = @TestObjectId)) begin set @new_id = @TestObjectId exec [dbo].[sp_TestSetupObjectsUpdate] @TestSetupId ,@TestObjectId ,@TestObjectName ,@TestSetupName ,@TargetSampleRate ,@ExcitationWarmupTimeMS ,@LocalOnly ,@TestObjectType ,@TestObjectPosition ,@DisplayOrder ,@errorNumber output ,@errorMessage output end else begin exec [dbo].[sp_TestSetupObjectsInsert] @TestSetupId ,@TestObjectId ,@TestObjectName ,@TestSetupName ,@TargetSampleRate ,@ExcitationWarmupTimeMS ,@LocalOnly ,@TestObjectType ,@TestObjectPosition ,@DisplayOrder ,@new_id output ,@errorNumber output ,@errorMessage output end END