USE [DataPro]
GO
/****** Object:  StoredProcedure [dbo].[sp_TestSetupGroupsUpdate]    Script Date: 6/14/2019 3:58:28 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[sp_TestSetupGroupsUpdate]
	@GroupId			INT,
	@TestSetupId		INT,
	@DisplayOrder		INT,
	@Position			VARCHAR(1) = NULL,
	@TestObjectType		VARCHAR(1) = NULL,
	@errorNumber		INT OUTPUT,
	@errorMessage		NVARCHAR (255) OUTPUT
AS
BEGIN
	SET NOCOUNT ON;
	SET @errorNumber=0
	SET @errorMessage=''
	
	IF ((@Position IS NOT NULL) and (@TestObjectType IS NOT NULL))
	BEGIN
		UPDATE [dbo].[TestSetupGroups] SET DisplayOrder=@DisplayOrder, Position=@Position, TestObjectType=@TestObjectType WHERE GroupId=@GroupId AND TestSetupId=@TestSetupId
	END
	ELSE IF (@Position IS NOT NULL)
	BEGIN
		UPDATE [dbo].[TestSetupGroups] SET DisplayOrder=@DisplayOrder, Position=@Position WHERE GroupId=@GroupId AND TestSetupId=@TestSetupId
	END
	ELSE IF (@TestObjectType IS NOT NULL)
	BEGIN
		UPDATE [dbo].[TestSetupGroups] SET DisplayOrder=@DisplayOrder, TestObjectType=@TestObjectType WHERE GroupId=@GroupId AND TestSetupId=@TestSetupId
	END
	ELSE -- They're both NULL
	BEGIN
		UPDATE [dbo].[TestSetupGroups] SET DisplayOrder=@DisplayOrder WHERE GroupId=@GroupId AND TestSetupId=@TestSetupId
	END

	IF(@@error != 0)
	BEGIN
		set @errorNumber = error_number()
		set @errorMessage = error_message()
	END
END