﻿-- =============================================
-- Author:		Steamware - S.E.L.
-- Create date: 2014.04.23
-- Description:	recupera record min/max per qta batch dato intervallo di analisi
-- =============================================
CREATE PROCEDURE [dbo].[stp_QLF_getMinMax]
(
	@DateMin	INT, -- formato aammgg
	@DateMax	INT  -- formato aammgg
)
AS

WITH cteMin AS
(
SELECT	TOP 1 * 
FROM	v_QuoteFull_Q
WHERE	CodQuote BETWEEN @DateMin AND @DateMax
ORDER BY BatchQty 
)
, cteMax AS
(
SELECT	TOP 1 * 
FROM	v_QuoteFull_Q
WHERE	CodQuote BETWEEN @DateMin AND @DateMax
ORDER BY BatchQty DESC
)

SELECT * FROM cteMin
UNION
SELECT * FROM cteMax

RETURN