-- FUNZIONI!

set ANSI_NULLS on;
go

/***************************************
* FUNCTION f_sumAllocSett
*
* calcola il totale sommando i valori dei singoli caratteri numerici (max 7 = settimanale)
*
* Steamware, S.E.L.
* mod: 2013.09.03
*
****************************************/
create FUNCTION f_sumAllocSett (@valore INT)
RETURNS INT AS  
BEGIN

    DECLARE @valStr NCHAR(7)
    DECLARE @oreWeek AS INT = 0

    SELECT @valStr = dbo.f_padLeft(@valore, 7, 0)

    select @oreWeek = CAST(RIGHT(LEFT(@valStr,1),1)  AS INT) 
                    + CAST(RIGHT(LEFT(@valStr,2),1)  AS INT) 
                    + CAST(RIGHT(LEFT(@valStr,3),1)  AS INT) 
                    + CAST(RIGHT(LEFT(@valStr,4),1)  AS INT) 
                    + CAST(RIGHT(LEFT(@valStr,5),1)  AS INT) 
                    + CAST(RIGHT(LEFT(@valStr,6),1)  AS INT) 
                    + CAST(RIGHT(LEFT(@valStr,7),1)  AS INT) 

    RETURN @oreWeek

END
go





-- registro versione...
INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(190, GETDATE())
GO
SELECT TOP 10 * FROM LogUpdateDb ORDER BY Versione DESC
GO
