• The reason your Where clause isn't working as expected is the OR statements need to be in parenthesis. Add an open paren "(" before the first "YEAR" and ")" after "2005". Then it should work as desired.

    The way it's written, it selects where "RUT_CLIE" is in the values selected and the year is 2007, or if the year is 2006 or the year is 2005. If the year was 2005 or 2006, it ignores the RUT_CLIE value, because of the way the OR statements are set up. Parentheses will fix that.

    You could also change it to " AND YEAR(DOCTOS.FEC_VCTO) in (2007, 2006, 2005)" and get rid of the OR statements, and it would also start to work as desired. (SQL will work exactly the same for each, but the IN statement might be easier to read and maintain.)

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon