USE UsineFlex_DW
GO
DROP VIEW IF EXISTS vue_FaitProduction
GO
CREATE VIEW vue_FaitProduction
AS
SELECT
P.NoProduit,
U.NoUsine,
LP.DateProduction,
M.NoMachine,
LP.Quantite,
LP.UnitesEnergieConsommees,
COUNT(EE.NoEntretienEffectue) AS NombreEntretiensEffectues,
SUM(DATEDIFF(HOUR, EE.DHDebut, EE.DHFinReelle) * E.SalaireHoraire) AS CoutEntretiensEffectues
FROM
UsineFlexInc.dbo.ff_EntretienEffectue EE
JOIN UsineFlexInc.dbo.ff_Machine M ON M.NoMachine = EE.NoMachine
JOIN UsineFlexInc.dbo.ff_Usine U ON U.NoUsine = M.NoUsine
JOIN UsineFlexInc.dbo.ff_LotProduction LP ON LP.NoMachine = M.NoMachine
JOIN UsineFlexInc.dbo.ff_Produit P ON P.NoProduit = LP.NoProduit
JOIN UsineFlexInc.dbo.ff_Employe E ON E.NoEmploye = EE.NoEmploye
WHERE
LP.DateModification > (
SELECT DateModification
FROM UsineFlex_ETLConfig
WHERE nomTable = 'FAIT_PRODUCTION'
)
GROUP BY
P.NoProduit,
U.NoUsine,
LP.DateProduction,
M.NoMachine,
LP.Quantite,
LP.UnitesEnergieConsommees;
-- Charger les données dans la table de fait à partir de la vue
INSERT INTO FAIT_PRODUCTION (RefProduit, RefNoUsine, RefDateProduction, NoMachine, Quantite, UnitesEnergieConsommees, NombreEntretiensEffectues, CoutEntretiensEffectues)
SELECT P.RefProduit, U.RefNoUsine, D.RefDate, FP.NoMachine, FP.Quantite, FP.UnitesEnergieConsommees, FP.NombreEntretiensEffectues, FP.CoutEntretiensEffectues
FROM vue_FaitProduction FP
INNER JOIN DIM_PRODUIT P ON(P.NoProduit = FP.NoProduit) AND P.Statut = 'Courant'
INNER JOIN DIM_USINE U ON (U.NoUsine = FP.NoUsine)
INNER JOIN DIM_DATE D ON D.RefDate = FP.DateProduction
UPDATE UsineFlex_ETLConfig
SET DateModification = getdate()
WHERE nomTable = 'FAIT_PRODUCTION'
GO
I get an error code for near the INSERT section, but I don't know why. Here is the error code:
Msg 156, Level 15, State 1, Procedure vue_FaitProduction, Line 38 [Batch Start Line 331] Incorrect syntax near the keyword 'INSERT'.