1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| CREATE TRIGGER E_EXR_IU
ON tblExchangeRate_EXR
FOR INSERT, UPDATE
AS
BEGIN
UPDATE tblExchangeRate_EXR
SET EXR.EXR_MonthImport = CASE -- Changement d'annee
When CAST(RIGHT(EXR.EXR_MonthCode,2) as SMALLINT) = 12
Then CAST(CAST(LEFT(EXR.EXR_MonthCode,4) AS SMALLINT)+1 AS CHAR(4))+ '01'
else
CASE -- Mois longeur < 2
When CAST(RIGHT(EXR.EXR_MonthCode,2) AS SAMLLINT) < 9
then LEFT(EXR.EXR_MonthCode,4)+'0'+CAST(CAST(RIGHT(EXR.EXR_MonthCode,2) AS SMALLINT)+1 AS CHAR(1))
else LEFT(EXR.EXR_MonthCode,4)+CAST(CAST(RIGHT(EXR.EXR_MonthCode,2) AS SMALLINT)+1 AS CHAR(2))
END
END
from tblExchangeRate_EXR EXR
INNER JOIN inserted i
on EXR.EXR_MonthCode = i.EXR_MonthCode;
END;
GO |