PDC_REPORT_CreazioneDB/sql/Produzione/funzioni/dbo_getNumSollecitiNOMIG.sql
2025-06-10 16:47:41 +02:00

39 lines
1.1 KiB
Transact-SQL

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[getNumSollecitiNOMIG]
(
-- {1,2,3,S}
@TipoSollecito char
)
RETURNS smallint
AS
BEGIN
DECLARE @numSoll smallint
DECLARE @NUMGIORNIDASOLLECITO smallint
DECLARE @TipoNumSoll smallint
SET @numSoll = 0
SET @NUMGIORNIDASOLLECITO = CAST(dbo.getParametro('NUMGIORNIDASOLLECITO') as smallint) --7
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 = 'N' 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 = 'N' and
DATEDIFF(day,C6.Data_Perf,GETDATE()) >= @NUMGIORNIDASOLLECITO * (numSolleciti + 1)
END
RETURN @numSoll
END