CREATE procedure [dbo].[GetTextTemplateConfiguration](@Rete varchar(1), @Tipo int, @Trimestrale int, @FieldName varchar(15))
as
begin
SELECT top (1) ttc.TextValue
FROM  dbo.ReportTemplate rt inner join dbo.TextTemplateConfigurationMapping ttcm on rt.TemplateID = ttcm.TemplateID
							inner join dbo.TextTemplateConfiguration ttc on ttc.TextFieldID = ttcm.TextFieldID
WHERE 
	(@Rete like rt.Rete) and 
	(@Trimestrale = rt.IsTrimestrale or rt.IsTrimestrale = -1) and 
	(@Tipo = rt.ContractType or rt.ContractType = -1) and 
	(@FieldName = ttc.TextFieldName)
END