﻿-- =============================================
-- STORED PROCEDURE stp_QL_fullDataSearch
--
-- Author:		Steamware
-- Create date: 2014.02.11
-- Description:	Recupera tutti i dati dalle tab QuoteList x avere schema con ricerca x cliente, item, materiale
-- =============================================
CREATE PROCEDURE [dbo].[stp_QL_fullDataSearch]
(
	  @CodClient NVARCHAR(50) = ''
	, @CodItem	NVARCHAR(50) = ''
	, @RawMat	NVARCHAR(50) = ''
	, @DataMin	DATETIME
	, @DataMax	DATETIME
)
AS
SET NOCOUNT ON

-- calcolo con aggiunta campi sommati...
SELECT *	
FROM v_QuoteFull_Q
WHERE CodClient = CASE WHEN ISNULL(@CodClient,'') = '' THEN CodClient ELSE @CodClient END
	AND CodItem = CASE WHEN ISNULL(@CodItem,'') = '' THEN CodItem ELSE @CodItem END
	AND RawMat = CASE WHEN ISNULL(@RawMat,'') = '' THEN RawMat ELSE @RawMat END
	--AND CodQuote BETWEEN CONVERT(NVARCHAR(30), @DataMin, 12)*10000 AND (CONVERT(NVARCHAR(30), @DataMax, 12) +1 )*10000 -- FARE FILTRO DATE!!! non c'è vero campo data...

RETURN
