-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[getNumSollecitiNOASS]
(
	-- {1,2,3,S}
	@TipoSollecito char
)
RETURNS smallint
AS
BEGIN
	DECLARE @numSoll smallint
	DECLARE @NUMGIORNIDASOLLECITO smallint
	set @numSoll = 0
	SET @NUMGIORNIDASOLLECITO = CAST(dbo.getParametro('NUMGIORNIDASOLLECITO') as smallint) --7
	DECLARE @TipoNumSoll smallint
		if (@TipoSollecito = '1' or @TipoSollecito = '2' or @TipoSollecito = '3') 
			BEGIN
				SET @tipoNumSoll = CAST(@TipoSollecito as smallint)
				select @numSoll =  count(*) from c6mart.contrattosei c6 where numSolleciti = @tipoNumSoll -1 and c6.clienteMigrato = 'S' and c6.risorseNA = 'S' and DATEDIFF(day,C6.Data_Perf,GETDATE()) >= @NUMGIORNIDASOLLECITO * @tipoNumSoll
			END
		if @TipoSollecito = 'S'
			BEGIN
				select @numSoll =  count(*) from c6mart.contrattosei c6 where numSolleciti > 2 and c6.clienteMigrato = 'S' and c6.risorseNA = 'S'and DATEDIFF(day,C6.Data_Perf,GETDATE()) >= @NUMGIORNIDASOLLECITO * (numSolleciti + 1)
			END
	RETURN @numSoll
END