• Gazareth (8/23/2012)


    Assuming you're using the DATE datatype, any of these:

    WHERE YEAR(DateField) IN (2011, 2012)

    WHERE YEAR(DateField) BETWEEN 2011 AND 2012

    WHERE DateField BETWEEN '20110101' AND '20121231'

    If there's an index on the DateField, the last one will perform the best, as the use of the YEAR function precludes the use of the index.

    If you're using DATETIME, the last one would become:

    WHERE DateField >= '20110101' AND DateField < '20130101'

    Cheers

    The first two will kill the use of any index on DateField. The third will work, but even with the DATE data type I'd prefer the method you suggested for the DATETIME data type.

    But have to agree with laurie-789651 as well, a better definition of what is requested would help.