This my my table
INSERT INTO Paiment (PaimentDate, Champs1, Champs2, Champs3)
VALUES (2013, 90, 70, 60), (2011, 20, 30, 40), (2009, 50, 0, 60),
(2008, 60, 16, 60), (2007, 0, 36, 20), (2006, 30, 25, 63),
(2017, 10, 70, 40), (2019, 20, 30, 32), (2030, 50, 0, 63),
(2020, 60, 16, 22), (2018, 0, 36, 33), (2005, 30, 25, 17)
When the entrydate
is before 2005, make sum champs1 and champs2 with paimentDate
lower to 2009.
Otherwise the entrydate
is greater than or equal to 2005, make sum the amounts of champs1 with paimentDate
lower than 2003 + the amount champs2 with paimentDate
lower than 2001
This is my code , please anybody could help me.
select
(Case
when DateofEntry < 2011 AND PaimentDate < 2005
Then (IsNull(Champs1, 0) + IsNull(Champs2, 0)
Else (case when DateofEntry >= 2001
Then (
(CASE WHEN PaimentDate < 2009 THEN ISNULL(Champs1.E1, 0) ELSE 0 END
+
CASE WHEN PaimentDate < 2011 THEN ISNULL(Champs2.E3, 0) ELSE 0 END)
)
end)
End)
this is my code . the probleme is when the paiementDate is lower than 2005, it must make sum of all element in champs1 + champs2 with paiment lower than 2005. but in this code , it makes sum of all champs1 + champs2 even if the paiement is higher than 2005 and that is not what i am looking for .
Any help please