IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_CalculatedChannelsUpdateInsert]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[sp_CalculatedChannelsUpdateInsert] 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_CalculatedChannelsUpdateInsert]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[sp_CalculatedChannelsUpdateInsert] AS' END GO ALTER PROCEDURE [dbo].[sp_CalculatedChannelsUpdateInsert] @id int = 0 ,@Operation int ,@CalculatedChannelValueCode nvarchar(255) ,@InputChannelIds varbinary(max) ,@CFCForInputChannels nvarchar(255) ,@CFCForOutput nvarchar(255) ,@TestSetupName nvarchar(255) ,@CCName nvarchar(255) ,@new_id int OUTPUT ,@errorNumber int output ,@errorMessage nvarchar(250) output AS BEGIN SET NOCOUNT ON; set @errorNumber = 0 set @errorMessage = space(0) if(@Operation is null or @TestSetupName is null) begin RAISERROR(15600,-1,-1, 'sp_CalculatedChannelsUpdateInsert') /* Error 1560 - An invalid parameter or option was specified for procedure*/ end else begin if(@id != 0 and exists(select Id from [dbo].[CalculatedChannels] where Id = @id)) begin set @new_id = @id exec [dbo].[sp_CalculatedChannelsUpdate] @id ,@Operation ,@CalculatedChannelValueCode ,@InputChannelIds ,@CFCForInputChannels ,@CFCForOutput ,@TestSetupName ,@CCName ,@errorNumber output ,@errorMessage output end else begin exec [dbo].[sp_CalculatedChannelsInsert] @Operation ,@CalculatedChannelValueCode ,@InputChannelIds ,@CFCForInputChannels ,@CFCForOutput ,@TestSetupName ,@CCName ,@new_id OUTPUT ,@errorNumber output ,@errorMessage output end end END GO