
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[p_grid_pr_products_variables_history]
    @product_code ais_code_short,
    @variable_code ais_code_short,
    @variable_date_setup datetime
AS 
	/*
	[DGE] - variable history, order by date setup - descending
	if @variable_date_setup = nullDate ( < 01/01/1900 ) - the procedure returns all history lines
	*/
	
	select	*
	from	pr_products_variables
		inner join nm_products_variables on prdv_variable_code = nmpv_variable_code
		inner join nm_products_variables_types on nmpv_type_code = nmpvt_type_code
	where	prdv_product_code = @product_code
	and		prdv_variable_code = @variable_code
	and		( @variable_date_setup IS NULL or prdv_variable_date_setup <= @variable_date_setup )
	order by prdv_variable_date_setup desc

GO
