﻿CREATE PROCEDURE [dbo].[sp_DiagnosticRunsGet]
	@Id					bigint	        = null,
	@TestId             int             = null,
	@TestName           nvarchar        = null
AS
BEGIN
	SET NOCOUNT ON;
	if( @Id IS NULL)
	BEGIN
		IF NULLIF(@Id, '') IS NULL
		BEGIN
			IF NULLIF(@TestName, '') IS NULL
			BEGIN
				IF(@TestId IS NULL)
				BEGIN
					SELECT [Id], [DataPROUser], [TestId], [TestName], [PreTest] from [dbo].DiagnosticRuns;
				END
				ELSE
				BEGIN
					SELECT [Id], [DataPROUser], [TestId], [TestName], [PreTest] from [dbo].DiagnosticRuns WHERE [TestId]=@TestId;
				END
			END			
			ELSE
			BEGIN
				SELECT [Id], [DataPROUser], [TestId], [TestName], [PreTest] from [dbo].DiagnosticRuns WHERE [TestName]=@TestName;
			END
		END
		ELSE
		BEGIN
			SELECT [Id], [DataPROUser], [TestId], [TestName], [PreTest] from [dbo].DiagnosticRuns WHERE [Id]=@Id;
		END
	END
	ELSE
	BEGIN
		SELECT [Id], [DataPROUser], [TestId], [TestName], [PreTest] from [dbo].DiagnosticRuns;
	END
END