set xact_abort on; go begin transaction; go set ANSI_NULLS on; go /********************************************************** * STORED stp_import_paymoRaw * * importa tracciato dati da paymo x utente e date indicate * * mod: S.E.L. 2012.11.20 * **********************************************************/ alter PROCEDURE import.stp_import_PaymoDataRaw ( @inizio DATETIME, @fine DATETIME ) AS /************************************************** * inizio importando eventuali clienti... **************************************************/ ;WITH myCteClienti AS ( SELECT DISTINCT Cliente FROM zzz_RawDataPaymo ) INSERT INTO AnagClienti(RagSociale, nota, Attivo) SELECT cte.Cliente, cte.Cliente, 1 FROM AnagClienti anag RIGHT OUTER JOIN myCteClienti cte ON anag.RagSociale = cte.Cliente WHERE anag.idxCliente IS NULL /************************************************** * importo eventuali progetti **************************************************/ ;WITH myCteProgetti AS ( SELECT DISTINCT Cliente, Progetto FROM zzz_RawDataPaymo ) INSERT INTO AnagProgetti(idxCliente, nomeProj, descrProj, Attivo) SELECT cli.idxCliente, cte.Progetto, cte.Progetto, 1 FROM AnagProgetti anag RIGHT OUTER JOIN myCteProgetti cte ON anag.nomeProj = cte.Progetto INNER JOIN AnagClienti Cli ON Cli.RagSociale = cte.Cliente WHERE anag.idxProgetto IS NULL /************************************************** * importo eventuali fasi **************************************************/ ;WITH myCteFasi AS ( SELECT DISTINCT Cliente, Progetto, TaskList FROM zzz_RawDataPaymo ) INSERT INTO AnagFasi(idxProgetto, codFase, nomeFase, descrizioneFase, enableTime, enableMoney, Attivo) SELECT Pro.idxProgetto, '', cte.TaskList, cte.TaskList, 1, 0, 1 FROM myCteFasi cte INNER JOIN AnagClienti Cli ON cte.Cliente = Cli.RagSociale INNER JOIN AnagProgetti Pro ON cte.Progetto = Pro.nomeProj LEFT OUTER JOIN AnagFasi anag ON anag.nomeFase = cte.TaskList AND anag.idxProgetto=pro.idxProgetto WHERE anag.idxFase IS NULL /************************************************** * importo eventuali sottofasi **************************************************/ ;WITH myCteSubFasi AS ( SELECT DISTINCT Cliente, Progetto, TaskList, Task FROM zzz_RawDataPaymo ) INSERT INTO AnagFasi(idxProgetto, idxFaseAncest, codFase, nomeFase, descrizioneFase, enableTime, enableMoney, Attivo) SELECT Pro.idxProgetto, Fas.idxFase as idxFaseAncest, '', cte.task, cte.task, 1, 0, 1 FROM myCteSubFasi cte INNER JOIN AnagClienti Cli ON cte.Cliente = Cli.RagSociale INNER JOIN AnagProgetti Pro ON cte.Progetto = Pro.nomeProj -- and pro.idxCliente=cli.idxCliente INNER JOIN AnagFasi Fas ON Fas.nomeFase = cte.TaskList AND Fas.idxProgetto = Pro.idxProgetto AND Fas.idxFaseAncest=0 LEFT OUTER JOIN AnagFasi anag ON anag.nomeFase = cte.Task AND anag.idxFaseAncest = Fas.idxFase WHERE anag.idxFaseAncest IS NULL /************************************************** * importo records! **************************************************/ INSERT INTO RegAttivita(idxDipendente, idxFase, inizio, fine, descrizione) SELECT Dip.idxDipendente, SFas.idxFase, cte.Inizio, cte.Fine, cte.Descrizione FROM zzz_RawDataPaymo cte INNER JOIN Dipendenti Dip ON cte.Dipendente = dip.codDipendenteExt INNER JOIN AnagClienti Cli ON cte.Cliente = Cli.RagSociale INNER JOIN AnagProgetti Pro ON cte.Progetto = Pro.nomeProj -- and pro.idxCliente=cli.idxCliente INNER JOIN AnagFasi Fas ON Fas.nomeFase = cte.TaskList AND Fas.idxProgetto = Pro.idxProgetto AND Fas.idxFaseAncest=0 INNER JOIN AnagFasi SFas ON SFas.nomeFase = cte.Task AND SFas.idxProgetto = Pro.idxProgetto AND SFas.idxFaseAncest=fas.idxFase LEFT OUTER JOIN RegAttivita dati ON dati.inizio = cte.Inizio AND dati.fine = cte.Fine AND dati.descrizione = cte.Descrizione AND dati.idxDipendente = Dip.idxDipendente WHERE dati.idxRA IS NULL RETURN go commit; go set xact_abort on; go begin transaction; go alter table AnagFasi add budgetTime decimal(19,4); go exec sp_addextendedproperty 'MS_Description', 'Budget del progetto (in ore)', 'SCHEMA', 'dbo', 'TABLE', 'AnagFasi', 'COLUMN', 'budgetTime'; go alter table AnagFasi add budgetMoney decimal(19,4); go set ANSI_NULLS on; go /********************************************************** * STORED stp_AF_getByIdxProj * * elenco fasi da progetto * * mod: S.E.L. 2012.10.31 * **********************************************************/ alter PROCEDURE stp_AF_getByIdxProj ( @idxProgetto INT ) AS SET NOCOUNT ON; /* SELECT idxFase, idxProgetto, codFase, idxFaseAncest, nomeFase, descrizioneFase, enableTime, enableMoney, Attivo, codClasse, codExt FROM AnagFasi WHERE (idxProgetto = @idxProgetto) ORDER BY codFase */ -- dichiaro variabili "accessorie" DECLARE @idxDipendente INT = 0 -- 0 = tutti DECLARE @dataFrom DATETIME = '19000101' DECLARE @dataTo DATETIME = '99991231' -- controllo se date nulle importo a min/max DECLARE @firstDate DATETIME DECLARE @lastDate DATETIME SELECT @firstDate = MIN(inizio), @lastDate=DATEADD(DAY,1,MAX(inizio)) FROM RegAttivita SELECT @dataFrom = ISNULL(@dataFrom, @firstDate), @dataTo=ISNULL(@dataTo, @lastDate) ;WITH myCTE AS ( SELECT af.idxFase, SUM(ISNULL(ra.oreTot, 0)) AS totOre FROM AnagFasi AS af INNER JOIN RegAttivita AS ra ON af.idxFase = ra.idxFase WHERE (ra.idxDipendente = @idxDipendente OR @idxDipendente = 0) AND (ra.inizio >= @dataFrom AND ra.inizio <= @dataTo) AND (af.idxProgetto = @idxProgetto OR @idxProgetto = 0) GROUP BY af.idxFase ) SELECT af.idxFase , af.idxProgetto , af.codFase , af.idxFaseAncest , af.nomeFase , af.descrizioneFase , af.enableTime , af.enableMoney , af.Attivo , ISNULL(af.budgetTime,0) AS budgetTime , ISNULL(af.budgetMoney,0) AS budgetMoney , ISNULL(af.codClasse,'') AS codClasse , ISNULL(af.codExt, '') AS codExt , ISNULL(cte.totOre, 0) AS totOre FROM AnagFasi AS af LEFT OUTER JOIN myCte AS cte ON cte.idxFase = af.idxFase WHERE (af.idxProgetto = @idxProgetto OR @idxProgetto = 0) ORDER BY af.nomeFase , af.codFase go /********************************************************** * STORED stp_AF_getByIdxFase * * recupera fasi da idx * * mod: S.E.L. 2012.11.12 * **********************************************************/ alter PROCEDURE stp_AF_getByIdxFase ( @idxFase INT ) AS SET NOCOUNT ON; /* SELECT * FROM AnagFasi WHERE @idxFase = idxFase */ -- dichiaro variabili "accessorie" DECLARE @idxDipendente INT = 0 -- 0 = tutti DECLARE @dataFrom DATETIME = '19000101' DECLARE @dataTo DATETIME = '99991231' -- controllo se date nulle importo a min/max DECLARE @firstDate DATETIME DECLARE @lastDate DATETIME SELECT @firstDate = MIN(inizio), @lastDate=DATEADD(DAY,1,MAX(inizio)) FROM RegAttivita SELECT @dataFrom = ISNULL(@dataFrom, @firstDate), @dataTo=ISNULL(@dataTo, @lastDate) ;WITH myCTE AS ( SELECT af.idxFase, SUM(ISNULL(ra.oreTot, 0)) AS totOre FROM AnagFasi AS af INNER JOIN RegAttivita AS ra ON af.idxFase = ra.idxFase WHERE (ra.idxDipendente = @idxDipendente OR @idxDipendente = 0) AND (ra.inizio >= @dataFrom AND ra.inizio <= @dataTo) AND (af.idxFase = @idxFase) GROUP BY af.idxFase ) SELECT af.idxFase , af.idxProgetto , af.codFase , af.idxFaseAncest , af.nomeFase , af.descrizioneFase , af.enableTime , af.enableMoney , af.Attivo , ISNULL(af.budgetTime,0) AS budgetTime , ISNULL(af.budgetMoney,0) AS budgetMoney , ISNULL(af.codClasse,'') AS codClasse , ISNULL(af.codExt, '') AS codExt , ISNULL(cte.totOre, 0) AS totOre FROM AnagFasi AS af LEFT OUTER JOIN myCte AS cte ON cte.idxFase = af.idxFase WHERE (af.idxFase = @idxFase) go /********************************************************** * STORED stp_AF_Expl_getData * * recupera elenco fasi con filtraggio ore totali per * - dipendente * - periodo * * mod: S.E.L. 2013.01.31 * **********************************************************/ create PROCEDURE stp_AF_Expl_getData ( @idxDipendente INT = 0, -- 0 = tutti @dataFrom DATETIME = '19000101', @dataTo DATETIME = '99991231', @idxProgetto INT = 0 ) AS -- controllo se date nulle importo a min/max DECLARE @firstDate DATETIME DECLARE @lastDate DATETIME SELECT @firstDate = MIN(inizio), @lastDate=DATEADD(DAY,1,MAX(inizio)) FROM RegAttivita SELECT @dataFrom = ISNULL(@dataFrom, @firstDate), @dataTo=ISNULL(@dataTo, @lastDate) ;WITH myCTE AS ( SELECT af.idxFase, SUM(ISNULL(ra.oreTot, 0)) AS totOre FROM AnagFasi AS af INNER JOIN RegAttivita AS ra ON af.idxFase = ra.idxFase WHERE (ra.idxDipendente = @idxDipendente OR @idxDipendente = 0) AND (ra.inizio >= @dataFrom AND ra.inizio <= @dataTo) AND (af.idxProgetto = @idxProgetto OR @idxProgetto = 0) GROUP BY af.idxFase ) SELECT af.idxFase , af.idxProgetto , af.codFase , af.idxFaseAncest , af.nomeFase , af.descrizioneFase , af.enableTime , af.enableMoney , af.Attivo , ISNULL(af.budgetTime,0) AS budgetTime , ISNULL(af.budgetMoney,0) AS budgetMoney , ISNULL(af.codClasse,'') AS codClasse , ISNULL(af.codExt, '') AS codExt , ISNULL(cte.totOre, 0) AS totOre FROM AnagFasi AS af LEFT OUTER JOIN myCte AS cte ON cte.idxFase = af.idxFase WHERE (af.idxProgetto = @idxProgetto OR @idxProgetto = 0) ORDER BY af.nomeFase , af.codFase go commit; go set xact_abort on; go begin transaction; go set ANSI_NULLS on; go alter VIEW v_selProgetti AS SELECT dbo.AnagProgetti.idxProgetto AS value, dbo.AnagClienti.RagSociale + ' - ' + dbo.AnagProgetti.nomeProj AS label, dbo.AnagClienti.idxCliente AS conditio FROM dbo.AnagClienti INNER JOIN dbo.AnagProgetti ON dbo.AnagClienti.idxCliente = dbo.AnagProgetti.idxCliente WHERE (dbo.AnagProgetti.Attivo = 1) go commit; go set xact_abort on; go begin transaction; go set ANSI_NULLS on; go /********************************************************** * STORED stp_AF_getLastByIdxDipendente * * elenco ULTIME fasi dato dipendente * * mod: S.E.L. 2012.11.09 * **********************************************************/ alter PROCEDURE stp_AF_getLastByIdxDipendente ( @idxDipendente INT, @num2show INT ) AS SET NOCOUNT ON; ;WITH myCTE AS( SELECT TOP(@num2show) * FROM RegAttivita WHERE idxDipendente = @idxDipendente ORDER BY inizio DESC ) SELECT *, 0 AS totOre FROM AnagFasi WHERE idxFase IN ( SELECT DISTINCT idxFase FROM myCTE UNION SELECT DISTINCT af.idxFaseAncest FROM AnagFasi af INNER JOIN myCTE ra ON af.idxFase=ra.idxFase ) ORDER BY codFase go /********************************************************** * STORED stp_AP_Expl_getData * * recupera elenco progetti con filtraggio ore totali per * - dipendente * - periodo * * mod: S.E.L. 2013.01.30 * **********************************************************/ alter PROCEDURE stp_AP_Expl_getData ( @idxDipendente INT = 0, -- 0 = tutti @dataFrom DATETIME = '19000101', @dataTo DATETIME = '99991231', @idxCliente INT = 0, -- 0 = tutti @showPrjArch BIT = 1 -- 1 = mostra tutti ) AS -- controllo se date nulle importo a min/max DECLARE @firstDate DATETIME DECLARE @lastDate DATETIME SELECT @firstDate = MIN(inizio), @lastDate=DATEADD(DAY,1,MAX(inizio)) FROM RegAttivita SELECT @dataFrom=ISNULL(@dataFrom, @firstDate) , @dataTo=ISNULL(@dataTo, @lastDate) ;WITH myCTE AS ( SELECT ap.idxProgetto, SUM(ISNULL(ra.oreTot, 0)) AS totOre FROM AnagProgetti AS ap INNER JOIN AnagClienti AS ac ON ac.idxCliente=ap.idxCliente INNER JOIN AnagFasi AS af ON ap.idxProgetto = af.idxProgetto INNER JOIN RegAttivita AS ra ON af.idxFase = ra.idxFase WHERE (ra.idxDipendente = @idxDipendente OR @idxDipendente = 0) AND (ra.inizio >= @dataFrom AND ra.inizio <= @dataTo) AND (ac.idxCliente = @idxCliente OR @idxCliente = 0) AND (ap.Attivo = CASE WHEN @showPrjArch <> 0 THEN ap.Attivo ELSE 1 END) GROUP BY ap.idxProgetto ) SELECT ac.RagSociale , ap.idxProgetto , ap.idxCliente , ap.nomeProj , ap.descrProj , ISNULL(ap.budgetTime,0) AS budgetTime , ISNULL(ap.budgetMoney,0) AS budgetMoney , ISNULL(ap.OldIdx,-1) AS OldIdx , ap.Attivo , ISNULL(ap.codExt,'') AS codExt , ISNULL(cte.totOre, 0) AS totOre , ISNULL(ap.avvio,'19000101') AS avvio , ISNULL(ap.chiusura,'99991231') AS chiusura FROM AnagClienti AS ac INNER JOIN AnagProgetti AS ap ON ac.idxCliente = ap.idxCliente LEFT OUTER JOIN myCte AS cte ON cte.idxProgetto = ap.idxProgetto WHERE (ac.idxCliente = @idxCliente OR @idxCliente = 0) AND (ap.Attivo = CASE WHEN @showPrjArch <> 0 THEN ap.Attivo ELSE 1 END) ORDER BY ac.RagSociale, ap.nomeProj go /********************************************************** * STORED stp_AP_getByIdxCli * * recupera elenco progetti da cliente * * mod: S.E.L. 2012.10.26 * **********************************************************/ alter PROCEDURE stp_AP_getByIdxCli ( @idxCliente INT, @showPrjArch BIT ) AS /* SELECT * FROM AnagProgetti WHERE idxCliente = CASE WHEN @idxCliente > 0 THEN @idxCliente ELSE idxCliente END AND Attivo = CASE WHEN @showPrjArch <> 0 THEN Attivo ELSE 1 END ORDER BY nomeProj */ ;WITH myCTE AS ( SELECT ap.idxProgetto, SUM(ISNULL(ra.oreTot, 0)) AS totOre FROM AnagProgetti AS ap INNER JOIN AnagClienti AS ac ON ac.idxCliente=ap.idxCliente INNER JOIN AnagFasi AS af ON ap.idxProgetto = af.idxProgetto INNER JOIN RegAttivita AS ra ON af.idxFase = ra.idxFase WHERE (ac.idxCliente = @idxCliente OR @idxCliente = 0) AND (ap.Attivo = CASE WHEN @showPrjArch <> 0 THEN ap.Attivo ELSE 1 END) GROUP BY ap.idxProgetto ) SELECT ac.RagSociale , ap.idxProgetto , ap.idxCliente , ap.nomeProj , ap.descrProj , ISNULL(ap.budgetTime,0) AS budgetTime , ISNULL(ap.budgetMoney,0) AS budgetMoney , ISNULL(ap.OldIdx,-1) AS OldIdx , ap.Attivo , ISNULL(ap.codExt,'') AS codExt , ISNULL(cte.totOre, 0) AS totOre , ISNULL(ap.avvio,'19000101') AS avvio , ISNULL(ap.chiusura,'99991231') AS chiusura FROM AnagClienti AS ac INNER JOIN AnagProgetti AS ap ON ac.idxCliente = ap.idxCliente LEFT OUTER JOIN myCte AS cte ON cte.idxProgetto = ap.idxProgetto WHERE (ac.idxCliente = @idxCliente OR @idxCliente = 0) AND (ap.Attivo = CASE WHEN @showPrjArch <> 0 THEN ap.Attivo ELSE 1 END) ORDER BY ac.RagSociale, ap.nomeProj go /********************************************************** * STORED stp_AP_getByIdxPrj * * recupera elenco progetti da idx * * mod: S.E.L. 2012.11.06 * **********************************************************/ alter PROCEDURE stp_AP_getByIdxPrj ( @idxProgetto INT ) AS /* SELECT * FROM AnagProgetti WHERE idxProgetto = @idxProgetto ORDER BY nomeProj */ ;WITH myCTE AS ( SELECT ap.idxProgetto, SUM(ISNULL(ra.oreTot, 0)) AS totOre FROM AnagProgetti AS ap INNER JOIN AnagClienti AS ac ON ac.idxCliente=ap.idxCliente INNER JOIN AnagFasi AS af ON ap.idxProgetto = af.idxProgetto INNER JOIN RegAttivita AS ra ON af.idxFase = ra.idxFase WHERE ap.idxProgetto = @idxProgetto GROUP BY ap.idxProgetto ) SELECT ac.RagSociale , ap.idxProgetto , ap.idxCliente , ap.nomeProj , ap.descrProj , ISNULL(ap.budgetTime,0) AS budgetTime , ISNULL(ap.budgetMoney,0) AS budgetMoney , ISNULL(ap.OldIdx,-1) AS OldIdx , ap.Attivo , ISNULL(ap.codExt,'') AS codExt , ISNULL(cte.totOre, 0) AS totOre , ISNULL(ap.avvio,'19000101') AS avvio , ISNULL(ap.chiusura,'99991231') AS chiusura FROM AnagClienti AS ac INNER JOIN AnagProgetti AS ap ON ac.idxCliente = ap.idxCliente INNER JOIN myCte AS cte ON cte.idxProgetto = ap.idxProgetto WHERE ap.idxProgetto = @idxProgetto go /********************************************************** * STORED stp_AP_insertQuery * * inserisce un progetto in anagrafica * * mod: S.E.L. 2013.01.30 * **********************************************************/ alter PROCEDURE stp_AP_insertQuery ( @idxCliente int, @nomeProj nvarchar(50), @descrProj nvarchar(250), @budgetTime decimal(19, 4), @budgetMoney decimal(19, 4), @avvio DATETIME = '19000101', @chiusura DATETIME = '99991231' ) AS SET NOCOUNT OFF; INSERT INTO AnagProgetti (idxCliente, nomeProj, descrProj, budgetTime, budgetMoney, Attivo, avvio, chiusura) VALUES (@idxCliente,@nomeProj,@descrProj,@budgetTime,@budgetMoney, 1, @avvio, @chiusura); --SELECT idxProgetto, idxCliente, nomeProj, descrProj, budgetTime, budgetMoney, OldIdx, Attivo FROM AnagProgetti WHERE (idxProgetto = SCOPE_IDENTITY()) DECLARE @idxPrj INT SELECT @idxPrj = SCOPE_IDENTITY() EXEC stp_AP_getByIdxPrj @idxPrj go /********************************************************** * STORED stp_AP_update * * elimina un progetto da anagrafica * * mod: S.E.L. 2013.01.30 * **********************************************************/ alter PROCEDURE stp_AP_update ( @idxCliente INT, @nomeProj NVARCHAR(50), @descrProj NVARCHAR(250), @budgetTime DECIMAL(19, 4), @budgetMoney DECIMAL(19, 4), @avvio DATETIME = '19000101', @chiusura DATETIME = '99991231', @Original_idxProgetto INT ) AS SET NOCOUNT OFF; UPDATE dbo.AnagProgetti SET idxCliente = @idxCliente, nomeProj = @nomeProj, descrProj = @descrProj, budgetTime = @budgetTime, budgetMoney = @budgetMoney, avvio = @avvio, chiusura = @chiusura WHERE idxProgetto = @Original_idxProgetto; /* SELECT idxProgetto, idxCliente, nomeProj, descrProj, budgetTime, budgetMoney, Attivo FROM AnagProgetti WHERE (idxProgetto =@Original_idxProgetto) */ EXEC stp_AP_getByIdxPrj @Original_idxProgetto go commit; go set xact_abort on; go begin transaction; go set ANSI_NULLS on; go /********************************************************** * STORED stp_AF_updateFaseAncest * * cambia la fase ancestor per una fase e le relative sottofasi dell'albero * * mod: S.E.L. 2013.01.31 * **********************************************************/ create PROCEDURE stp_AF_updateFaseAncest ( @idxFaseAncest INT, @Original_idxFase INT ) AS SET NOCOUNT OFF; UPDATE AnagFasi SET idxFaseAncest = @idxFaseAncest WHERE idxFase = @Original_idxFase; SELECT * FROM AnagFasi WHERE idxFase = @Original_idxFase go /********************************************************** * STORED stp_AF_updateProegtto * * cambia il progetto per una fase e le relative sottofasi dell'albero * * mod: S.E.L. 2013.01.31 * **********************************************************/ create PROCEDURE stp_AF_updateProgetto ( @idxProgetto INT, @Original_idxFase INT ) AS SET NOCOUNT OFF; UPDATE AnagFasi SET idxProgetto = @idxProgetto WHERE idxFase = @Original_idxFase; SELECT * FROM AnagFasi WHERE idxFase = @Original_idxFase go commit; go set xact_abort on; go begin transaction; go set ANSI_NULLS on; go /********************************************************** * STORED stp_RA_clonaLastRA_Utente * * clona un attivitā utente: se c'č da ultima altrimenti da zero x una certa data * * mod: S.E.L. 2013.01.17 * **********************************************************/ alter PROCEDURE stp_RA_clonaLastRA_Utente ( @idxDipendente INT, @dataRif DATETIME -- data x cui creare un record attivitā ) AS -- variabili DECLARE @idxFase INT DECLARE @idxRA INT -- arrotondo data richiesta solo all'ora... SELECT @dataRif = DATEADD(HOUR, DATEPART(HOUR,@dataRif), CONVERT(DATETIME,(CONVERT(DATE,@dataRif)))) -- cerco se esista ultima reg attivitā utente... SELECT @idxRA=ISNULL((SELECT TOP 1 idxRA FROM RegAttivita WHERE idxDipendente = @idxDipendente),0) -- se non ho trovato records, ovvero idxRA = 0, prendo ultima fase da elenco IF (@idxRA = 0) BEGIN -- calcolo ultima fase inserita... SELECT TOP 1 @idxFase=ISNULL(idxFase,0) FROM AnagFasi ORDER BY idxFase DESC -- se trovata fase inserisco! IF(@idxFase > 0) BEGIN INSERT INTO RegAttivita(idxDipendente, idxFase, inizio, fine, descrizione, importo) VALUES (@idxDipendente, @idxFase, @dataRif, DATEADD(HOUR,1,@dataRif), '...',0) END END ELSE BEGIN -- inserisco su data richeista duplicazione dell'ultima attivitā utente... INSERT INTO RegAttivita(idxDipendente, idxFase, inizio, fine, descrizione, importo) SELECT idxDipendente, idxFase, @dataRif, DATEADD(minute, DATEDIFF(MINUTE, inizio, fine), @dataRif), descrizione, importo FROM RegAttivita WHERE (idxRA = @idxRA) END go commit; go -- registro versione... INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(270, GETDATE()) GO SELECT * FROM LogUpdateDb ORDER BY Versione DESC