From 77be858f9c2d077dbcb84af6ba02be395220f4d6 Mon Sep 17 00:00:00 2001 From: samuele Date: Wed, 29 Jun 2011 16:33:20 +0000 Subject: [PATCH] =?UTF-8?q?COmpletate=20modifiche=20calcolo=20tempo=20senz?= =?UTF-8?q?a=20feste,=20sab=20e=20domeniche=20(x=20ora=20ok=20cos=C3=AC...?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://keyhammer.ath.cx/svn/WebGIM/trunk@182 3e04ef4b-3b25-4b6c-be27-bb5389ca777b --- Projects/WebGIM/GIM_site/sql/GIM_0008.sql | 590 ++++++++++++++++++++-- Projects/WebGIM/GIM_site/sql/GIM_0020.sql | 67 +++ 2 files changed, 615 insertions(+), 42 deletions(-) create mode 100644 Projects/WebGIM/GIM_site/sql/GIM_0020.sql diff --git a/Projects/WebGIM/GIM_site/sql/GIM_0008.sql b/Projects/WebGIM/GIM_site/sql/GIM_0008.sql index 7a45a9f..24e6a81 100644 --- a/Projects/WebGIM/GIM_site/sql/GIM_0008.sql +++ b/Projects/WebGIM/GIM_site/sql/GIM_0008.sql @@ -1,4 +1,164 @@ -set xact_abort on +create table AnagClasseTurno( + CodClasseTurno nvarchar(50) not null constraint PK_AnagClasseTurno primary key, + Descrizione nvarchar(50), + hSettStd int +) +go + + +set xact_abort on +go + +begin transaction +go + +INSERT INTO dbo.AnagClasseTurno + VALUES (N'2t5gg', N'2 turni, 5 gg', 80) +INSERT INTO dbo.AnagClasseTurno + VALUES (N'3t5gg', N'3 turni, 5 gg', 120) +go + +commit transaction +go + + +create table AnagTurni( + CodTurno nvarchar(50) not null constraint PK_AnagTurni primary key, + hStart int, + hEnd int, + descr nvarchar(50) +) +go + + +set xact_abort on +go + +begin transaction +go + +INSERT INTO dbo.AnagTurni + VALUES (N'T1', 6, 14, N'Turno 8h standard') +INSERT INTO dbo.AnagTurni + VALUES (N'T2', 14, 22, N'Turno 8h standard') +INSERT INTO dbo.AnagTurni + VALUES (N'T3', 22, 6, N'Turno 8h standard') +INSERT INTO dbo.AnagTurni + VALUES (N'TA', 0, 6, N'Turno 6h std') +INSERT INTO dbo.AnagTurni + VALUES (N'TB', 6, 12, N'Turno 6h std') +INSERT INTO dbo.AnagTurni + VALUES (N'TC', 12, 18, N'Turno 6h std') +INSERT INTO dbo.AnagTurni + VALUES (N'TD', 18, 24, N'Turno 6h std') +go + +commit transaction +go + + +drop table OreAperturaSett +go + + +create table OreAperturaSettTurni( + CodClasseTurno nvarchar(50) not null, + CodTurno nvarchar(50) not null, + giorno int not null, + descrGiorno nvarchar(50), + + constraint PK_OreAperturaSett primary key(CodClasseTurno,giorno,CodTurno) +) +go + + +set xact_abort on +go + +begin transaction +go + +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'2t5gg', N'T1', 1, N'Lun') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'2t5gg', N'T1', 2, N'Mar') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'2t5gg', N'T1', 3, N'Mer') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'2t5gg', N'T1', 4, N'Gio') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'2t5gg', N'T1', 5, N'Ven') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'2t5gg', N'T2', 1, N'Lun') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'2t5gg', N'T2', 2, N'Mar') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'2t5gg', N'T2', 3, N'Mer') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'2t5gg', N'T2', 4, N'Gio') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'2t5gg', N'T2', 5, N'Ven') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T1', 1, N'Lun') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T1', 2, N'Mar') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T1', 3, N'Mer') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T1', 4, N'Gio') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T1', 5, N'Ven') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T2', 1, N'Lun') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T2', 2, N'Mar') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T2', 3, N'Mer') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T2', 4, N'Gio') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T2', 5, N'Ven') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T3', 1, N'Lun') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T3', 2, N'Mar') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T3', 3, N'Mer') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T3', 4, N'Gio') +INSERT INTO dbo.OreAperturaSettTurni + VALUES (N'3t5gg', N'T3', 5, N'Ven') +go + +commit transaction +go + + +create table OreChiusuraSett( + giorno int not null constraint PK_OreAperturaSett_1 primary key, + descrGiorno nvarchar(50), + chiusura int +) +go + + +set xact_abort on +go + +begin transaction +go + +INSERT INTO dbo.OreChiusuraSett + VALUES (6, N'Sab', 16) +INSERT INTO dbo.OreChiusuraSett + VALUES (7, N'Dom', 24) +go + +commit transaction +go + + +set xact_abort on go begin transaction @@ -7,54 +167,398 @@ go set ANSI_NULLS on go -/************************************* -* STORED PROCEDURE sp_elencoIntMTBF_MTTR -* Restituisce elenco degli interventi x fare il calcolo MTBF/MTTR FILTRANDO per: -* - idxStati -* - idxImpianto -* - idxMacchina +/*********************************************************************************** +* FUNCTION f_dateOnly * -* modif.: S.E.L. - 2010.05.11 -**************************************/ -alter PROCEDURE sp_elencoIntMTBF_MTTR +* restituisce solo la parte data di un campo datetime (ovvero a mezzanotte...) +* +***********************************************************************************/ +create FUNCTION f_dateOnly ( - @inizio DATETIME, - @fine DATETIME, - @username VARCHAR(100) + @dateIn DATETIME ) +RETURNS DATETIME AS + BEGIN + RETURN dateadd(dd, -datediff(dd, @dateIn, 1), 1) + END +go - -- inizio con il creare la vista che mi serve x selezionare gli interventi filtrati dall'utente (per poterli escludere-includere) - WITH ElencoInt AS (SELECT v_elencoIntervFilt.* - FROM FiltroImpianti INNER JOIN - FiltroMacchine INNER JOIN - v_elencoIntervFilt INNER JOIN - FiltroStati ON v_elencoIntervFilt.idxStato = FiltroStati.idxStato ON FiltroMacchine.idxMacchina = v_elencoIntervFilt.idxMacchina ON - FiltroImpianti.idxImpianto = v_elencoIntervFilt.idxImpianto - WHERE (v_elencoIntervFilt.richiesta BETWEEN @inizio AND @fine) AND (FiltroStati.username = @username) AND (FiltroMacchine.username = @username) AND - (FiltroImpianti.username = @username)) +commit +go + +set xact_abort on +go + +begin transaction +go + +set ANSI_NULLS on +go + +/*********************************************************************************** +* FUNCTION f_diffOreLavorative +* +* calcola le effettive ore lavorative sottraendo chiusure x festività o aperture programmate +* +***********************************************************************************/ +create FUNCTION f_diffOreLavorative +( + @dataFrom DATETIME, + @dataTo DATETIME, + @idxMacchina INT -- per ora non lo considero poiché non ci sono calendari diversi x macchina... +) +RETURNS FLOAT +AS + BEGIN + + -- dichiarazioni variabili + DECLARE @oreTot AS FLOAT + DECLARE @oreOff AS FLOAT + DECLARE @tmp_dates TABLE (DateValue DATETIME, h INT) + SET @oreTot = 0 - -- seleziono gli interventi DAVVERO erogati - SELECT COUNT(ElencoInt.numIntMtz) AS numInterventi, SUM(ElencoInt.durataMtz) AS totOreMtz, - SUM(ElencoInt.durataOff) AS totOreOfficina, ElencoInt.codImpianto, ElencoInt.codMacchina, - ElencoInt.nomeImpianto, ElencoInt.nomeMacchina - FROM ElencoInt - GROUP BY ElencoInt.codImpianto, ElencoInt.codMacchina, ElencoInt.nomeImpianto, ElencoInt.nomeMacchina - - UNION - - -- seleziono gli impianti che NON hanno ricevuto interventi ma comunque scelti dall'utente... - SELECT 0 AS numInterventi, 0 AS totOreMtz, 0 AS totOreOfficina, AnagImpianti.codImpianto, AnagMacchine.codMacchina, AnagImpianti.nomeImpianto, - AnagMacchine.nomeMacchina - FROM FiltroMacchine INNER JOIN - AnagMacchine ON FiltroMacchine.idxMacchina = AnagMacchine.idxMacchina INNER JOIN - AnagImpianti ON AnagMacchine.idxImpianto = AnagImpianti.idxImpianto LEFT OUTER JOIN - ElencoInt ON FiltroMacchine.idxMacchina = ElencoInt.idxMacchina - WHERE (ElencoInt.numIntMtz IS NULL) - GROUP BY AnagImpianti.codImpianto, AnagMacchine.codMacchina, AnagImpianti.nomeImpianto, AnagMacchine.nomeMacchina + -- controllo date coerenti + IF(@dataTo > @dataFrom) + BEGIN + -- calcolo totale "raw" delle ore + SET @oreTot = CAST(ISNULL(DATEDIFF(minute, @dataFrom, @dataTo), 0) AS float) / 60; + -- definisco tabella cte ricorsiva + WITH mycte AS + ( + SELECT CAST(dbo.f_dateOnly(DATEADD(dd,1,@dataFROM)) AS DATETIME) DateValue + UNION ALL + SELECT DateValue + 1 + FROM mycte + WHERE DateValue + 1 < dbo.f_dateOnly(@dataTo) + ) + -- carico nella tab temporanea i sabati e le domeniche... + INSERT into @tmp_dates(DateValue, h) + SELECT *, CASE ((DATEPART(dw, DateValue) + @@DATEFIRST) % 7) WHEN 0 THEN 16 ELSE 24 END AS h + FROM mycte + WHERE ((DATEPART(dw, DateValue) + @@DATEFIRST) % 7) IN (0,1) + OPTION (MAXRECURSION 0) + -- carico le festività per le date NON ancora presenti + insert into @tmp_dates(DateValue, h) + select data as DateValue, 24 as h--, descrizione + from CalendFesteFerie + where data between @dataFrom and @dataTo and data not in (select distinct DateValue from @tmp_dates) + -- aggiorno sabati/domenica che fossero festivi (ipotesi che hfest > h sab/dom... + UPDATE @tmp_dates + SET h=24 + WHERE DateValue in (SELECT data FROM CalendFesteFerie WHERE data between @dataFrom and @dataTo) + + -- calcolo INFINE le ore off! + SET @oreOff = (SELECT ISNULL(SUM(h),0) FROM @tmp_dates) + END + -- setto le nuove ore totali... se ho un numero di ore > delle fermate le sottraggo per evitare ore engative... + IF(@oreTot > @oreOff) + BEGIN + SET @oreTot = @oreTot - @oreOff + END + + RETURN @oreTot + END -RETURN +/* + +declare @tmp_dates table (DateValue datetime, h int); +declare @dataFrom datetime +declare @dataTo datetime +set @dataFrom = '2011-04-01' +set @dataTo = '2011-07-01'; + +with mycte as +( + select cast(@dataFrom as datetime) DateValue, 16 as h--, 'sab/dom' as descrizione + union all + select DateValue + 1, 16 as h--, 'sab/dom' as descrizione + from mycte + where DateValue + 1 < @dataTo +) + +insert into @tmp_dates(DateValue, h) +select * +from mycte +where ((DATEPART(dw, DateValue) + @@DATEFIRST) % 7) IN (0, 1) +OPTION (MAXRECURSION 0); + + +insert into @tmp_dates(DateValue, h) +select data as DateValue, 24 as h--, descrizione +from CalendFesteFerie +where data between @dataFrom and @dataTo and data not in (select distinct DateValue from @tmp_dates); + +update @tmp_dates +set h=24 +where DateValue in (select data from CalendFesteFerie where data between @dataFrom and @dataTo) + +select * from @tmp_dates +order by DateValue + +*/ +go + +commit +go + + +set xact_abort on +go + +begin transaction +go + +set ANSI_NULLS on +go + +alter VIEW v_elencoIntervFilt +AS +SELECT TOP (100) PERCENT dbo.InterventiMtz.numIntMtz, dbo.InterventiMtz.richiesta, dbo.AnagImpianti.codImpianto, dbo.AnagImpianti.nomeImpianto, + dbo.AnagMacchine.codMacchina, dbo.AnagMacchine.nomeMacchina, dbo.InterventiMtz.descrizione, dbo.InterventiMtz.inizioIntervento, + dbo.InterventiMtz.fineIntervento, ISNULL(dbo.InterventiMtz.descrizioneIntervento, 'n.d. (report mtz)') AS descrizioneIntervento, + ISNULL(dbo.AnagCausali.descrCausale, 'n.d. (causale)') AS descrCausale, ROUND(CAST(ISNULL(dbo.v_interventiErogati.totMinErogati, 0) AS float) / 60, 2) + AS minErogati, dbo.f_diffOreLavorative(dbo.InterventiMtz.inizioIntervento, dbo.InterventiMtz.fineIntervento, dbo.InterventiMtz.idxMacchina) AS durataMtz, + CASE (isFermo) WHEN 1 THEN dbo.f_diffOreLavorative(dbo.InterventiMtz.guasto, dbo.InterventiMtz.fineIntervento, InterventiMtz.idxMacchina) + WHEN 0 THEN dbo.f_diffOreLavorative(dbo.InterventiMtz.inizioIntervento, dbo.InterventiMtz.fineIntervento, InterventiMtz.idxMacchina) END AS durataOff, + dbo.InterventiMtz.guasto, dbo.InterventiMtz.idxStato, dbo.InterventiMtz.idxImpianto, dbo.InterventiMtz.idxMacchina, dbo.InterventiMtz.isFermo, + dbo.InterventiMtz.scheduled +FROM dbo.InterventiMtz INNER JOIN + dbo.AnagAmbitoGuasto ON dbo.InterventiMtz.idxAmbito = dbo.AnagAmbitoGuasto.idxAmbito INNER JOIN + dbo.AnagImpianti ON dbo.InterventiMtz.idxImpianto = dbo.AnagImpianti.idxImpianto INNER JOIN + dbo.AnagMacchine ON dbo.InterventiMtz.idxMacchina = dbo.AnagMacchine.idxMacchina INNER JOIN + dbo.AnagTipoGuasto ON dbo.InterventiMtz.idxTipo = dbo.AnagTipoGuasto.idxTipo INNER JOIN + dbo.AnagPriorita ON dbo.InterventiMtz.idxPriorita = dbo.AnagPriorita.idxPriorita INNER JOIN + dbo.AnagStati ON dbo.InterventiMtz.idxStato = dbo.AnagStati.idxStato LEFT OUTER JOIN + dbo.v_interventiErogati ON dbo.InterventiMtz.numIntMtz = dbo.v_interventiErogati.numIntMtz LEFT OUTER JOIN + dbo.AnagCausali ON dbo.InterventiMtz.idxCausale = dbo.AnagCausali.idxCausale +ORDER BY dbo.InterventiMtz.numIntMtz DESC +go + +exec sp_updateextendedproperty 'MS_DiagramPane1', '[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00] +Begin DesignProperties = + Begin PaneConfigurations = + Begin PaneConfiguration = 0 + NumPanes = 4 + Configuration = "(H (1[40] 4[20] 2[20] 3) )" + End + Begin PaneConfiguration = 1 + NumPanes = 3 + Configuration = "(H (1 [50] 4 [25] 3))" + End + Begin PaneConfiguration = 2 + NumPanes = 3 + Configuration = "(H (1 [50] 2 [25] 3))" + End + Begin PaneConfiguration = 3 + NumPanes = 3 + Configuration = "(H (4 [30] 2 [40] 3))" + End + Begin PaneConfiguration = 4 + NumPanes = 2 + Configuration = "(H (1 [56] 3))" + End + Begin PaneConfiguration = 5 + NumPanes = 2 + Configuration = "(H (2 [66] 3))" + End + Begin PaneConfiguration = 6 + NumPanes = 2 + Configuration = "(H (4 [50] 3))" + End + Begin PaneConfiguration = 7 + NumPanes = 1 + Configuration = "(V (3))" + End + Begin PaneConfiguration = 8 + NumPanes = 3 + Configuration = "(H (1[56] 4[18] 2) )" + End + Begin PaneConfiguration = 9 + NumPanes = 2 + Configuration = "(H (1 [75] 4))" + End + Begin PaneConfiguration = 10 + NumPanes = 2 + Configuration = "(H (1[66] 2) )" + End + Begin PaneConfiguration = 11 + NumPanes = 2 + Configuration = "(H (4 [60] 2))" + End + Begin PaneConfiguration = 12 + NumPanes = 1 + Configuration = "(H (1) )" + End + Begin PaneConfiguration = 13 + NumPanes = 1 + Configuration = "(V (4))" + End + Begin PaneConfiguration = 14 + NumPanes = 1 + Configuration = "(V (2))" + End + ActivePaneConfig = 0 + End + Begin DiagramPane = + Begin Origin = + Top = 0 + Left = 0 + End + Begin Tables = + Begin Table = "AnagAmbitoGuasto" + Begin Extent = + Top = 11 + Left = 82 + Bottom = 89 + Right = 255 + End + DisplayFlags = 280 + TopColumn = 0 + End + Begin Table = "AnagImpianti" + Begin Extent = + Top = 123 + Left = 219 + Bottom = 231 + Right = 370 + End + DisplayFlags = 280 + TopColumn = 0 + End + Begin Table = "AnagMacchine" + Begin Extent = + Top = 190 + Left = 826 + Bottom = 298 + Right = 977 + End + DisplayFlags = 280 + TopColumn = 0 + End + Begin Table = "AnagTipoGuasto" + Begin Extent = + Top = 90 + Left = 1143 + Bottom = 168 + Right = 1294 + End + DisplayFlags = 280 + TopColumn = 0 + End + Begin Table = "AnagPriorita" + Begin Extent = + Top = 23 + Left = 958 + Bottom = 116 + Right = 1109 + End + DisplayFlags = 280 + TopColumn = 0 + End + Begin Table = "AnagStati" + Begin Extent = + Top = 263 + Left = 90 + Bottom = 356 + Right = 241 + End + DisplayFlags = 280 + TopColumn = 0 + End + Begin Table = "v_interventiErogati" + Begin Extent = + Top = 3 + Left = 739 + Bottom = 81 + Right = 890 + ', 'SCHEMA', 'dbo', 'VIEW', 'v_elencoIntervFilt' +go + +exec sp_updateextendedproperty 'MS_DiagramPane2', ' End + DisplayFlags = 280 + TopColumn = 0 + End + Begin Table = "AnagCausali" + Begin Extent = + Top = 291 + Left = 1011 + Bottom = 369 + Right = 1162 + End + DisplayFlags = 280 + TopColumn = 0 + End + Begin Table = "InterventiMtz" + Begin Extent = + Top = 8 + Left = 486 + Bottom = 354 + Right = 671 + End + DisplayFlags = 280 + TopColumn = 0 + End + End + End + Begin SQLPane = + End + Begin DataPane = + Begin ParameterDefaults = "" + End + Begin ColumnWidths = 30 + Width = 284 + Width = 915 + Width = 1815 + Width = 690 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1665 + Width = 1665 + Width = 1500 + Width = 1500 + Width = 1050 + Width = 1020 + Width = 1125 + Width = 1815 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + Width = 1500 + End + End + Begin CriteriaPane = + Begin ColumnWidths = 11 + Column = 1440 + Alias = 900 + Table = 1170 + Output = 720 + Append = 1400 + NewValue = 1170 + SortType = 1350 + SortOrder = 1410 + GroupBy = 1350 + Filter = 1350 + Or = 1350 + Or = 1350 + Or = 1350 + End + End +End +', 'SCHEMA', 'dbo', 'VIEW', 'v_elencoIntervFilt' go commit @@ -62,6 +566,8 @@ go + + -- registro versione... -INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(8, GETDATE()) +INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(20, GETDATE()) GO \ No newline at end of file diff --git a/Projects/WebGIM/GIM_site/sql/GIM_0020.sql b/Projects/WebGIM/GIM_site/sql/GIM_0020.sql new file mode 100644 index 0000000..7a45a9f --- /dev/null +++ b/Projects/WebGIM/GIM_site/sql/GIM_0020.sql @@ -0,0 +1,67 @@ +set xact_abort on +go + +begin transaction +go + +set ANSI_NULLS on +go + +/************************************* +* STORED PROCEDURE sp_elencoIntMTBF_MTTR +* Restituisce elenco degli interventi x fare il calcolo MTBF/MTTR FILTRANDO per: +* - idxStati +* - idxImpianto +* - idxMacchina +* +* modif.: S.E.L. - 2010.05.11 +**************************************/ +alter PROCEDURE sp_elencoIntMTBF_MTTR +( + @inizio DATETIME, + @fine DATETIME, + @username VARCHAR(100) +) +AS + + -- inizio con il creare la vista che mi serve x selezionare gli interventi filtrati dall'utente (per poterli escludere-includere) + WITH ElencoInt AS (SELECT v_elencoIntervFilt.* + FROM FiltroImpianti INNER JOIN + FiltroMacchine INNER JOIN + v_elencoIntervFilt INNER JOIN + FiltroStati ON v_elencoIntervFilt.idxStato = FiltroStati.idxStato ON FiltroMacchine.idxMacchina = v_elencoIntervFilt.idxMacchina ON + FiltroImpianti.idxImpianto = v_elencoIntervFilt.idxImpianto + WHERE (v_elencoIntervFilt.richiesta BETWEEN @inizio AND @fine) AND (FiltroStati.username = @username) AND (FiltroMacchine.username = @username) AND + (FiltroImpianti.username = @username)) + + + -- seleziono gli interventi DAVVERO erogati + SELECT COUNT(ElencoInt.numIntMtz) AS numInterventi, SUM(ElencoInt.durataMtz) AS totOreMtz, + SUM(ElencoInt.durataOff) AS totOreOfficina, ElencoInt.codImpianto, ElencoInt.codMacchina, + ElencoInt.nomeImpianto, ElencoInt.nomeMacchina + FROM ElencoInt + GROUP BY ElencoInt.codImpianto, ElencoInt.codMacchina, ElencoInt.nomeImpianto, ElencoInt.nomeMacchina + + UNION + + -- seleziono gli impianti che NON hanno ricevuto interventi ma comunque scelti dall'utente... + SELECT 0 AS numInterventi, 0 AS totOreMtz, 0 AS totOreOfficina, AnagImpianti.codImpianto, AnagMacchine.codMacchina, AnagImpianti.nomeImpianto, + AnagMacchine.nomeMacchina + FROM FiltroMacchine INNER JOIN + AnagMacchine ON FiltroMacchine.idxMacchina = AnagMacchine.idxMacchina INNER JOIN + AnagImpianti ON AnagMacchine.idxImpianto = AnagImpianti.idxImpianto LEFT OUTER JOIN + ElencoInt ON FiltroMacchine.idxMacchina = ElencoInt.idxMacchina + WHERE (ElencoInt.numIntMtz IS NULL) + GROUP BY AnagImpianti.codImpianto, AnagMacchine.codMacchina, AnagImpianti.nomeImpianto, AnagMacchine.nomeMacchina + +RETURN +go + +commit +go + + + +-- registro versione... +INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(8, GETDATE()) +GO \ No newline at end of file