Torna al Thread
CREATE PROCEDURE GER_get_PresenzeForReport
@idContratto int,
@mese int,
@anno int
AS
BEGIN
DECLARE @giorniMese int
DECLARE @giorno int
DECLARE @orePresenza smallmoney
DECLARE @tbResult table (giorno smalldatetime NOT NULL, nOreTotali smallmoney NOT NULL)
SET @giorniMese = dbo.BASE_get_GiorniFromMeseAnno (@anno, @mese)
SET @giorno = 1
WHILE (@giorno <= @giorniMese)
BEGIN
DECLARE @dataCorrente smalldatetime
SET @dataCorrente = dbo.BASE_get_SmallDateTime (@giorno, @mese, @anno)
SET @orePresenza = NULL
SELECT @orePresenza=nOreTotali FROM GER_PRESENZE WHERE (ID_Risorsa = @idContratto AND giorno = @dataCorrente)
IF (NOT (@orePresenza IS NULL))
BEGIN
INSERT INTO @tbResult (giorno, nOreTotali) VALUES (@dataCorrente, @orePresenza)
END
ELSE
BEGIN
INSERT INTO @tbResult (giorno, nOreTotali) VALUES (@dataCorrente, 0)
END
SET @giorno = @giorno + 1
END
SELECT giorno, nOreTotali FROM @tbResult ORDER BY giorno
END
GO