CREATE PROCEDURE [dbo].[sp_TestHistoryGet]
	@TestHistoryId			BIGINT = NULL,
	@TestSetupId			INT = NULL,
	@TestSetupName			NVARCHAR(50)=NULL,
	@Destructive        BIT = NULL
AS
BEGIN
	SET NOCOUNT ON;	
	IF @TestSetupId IS NOT NULL
	BEGIN
		SELECT [TestHistoryId], [TestSetupId], [TestSetupName], [TestSetupDescription], [TestId], [Destructive], [ArmTime], [TestSetup] FROM [dbo].TestHistory WHERE [TestSetupId]=@TestSetupId
	END
	ELSE
	BEGIN
		IF @Destructive IS NOT NULL
		BEGIN
			SELECT [TestHistoryId], [TestSetupId], [TestSetupName], [TestSetupDescription], [TestId], [Destructive], [ArmTime], [TestSetup] FROM [dbo].TestHistory WHERE [Destructive]=@Destructive
		END
		ELSE
		BEGIN
			IF @TestHistoryId IS NOT NULL
			BEGIN
				SELECT [TestHistoryId], [TestSetupId], [TestSetupName], [TestSetupDescription], [TestId], [Destructive], [ArmTime], [TestSetup] FROM [dbo].TestHistory WHERE [TestHistoryId]=@TestHistoryId
			END
			ELSE
				BEGIN
					SELECT [TestHistoryId], [TestSetupId], [TestSetupName], [TestSetupDescription], [TestId], [Destructive], [ArmTime], [TestSetup] FROM [dbo].TestHistory WHERE [TestSetupName]=@TestSetupName
				END
		END
	END
END