Posted by --CELKO-- on 03/15/07 22:41
SELECT DATEPART(yy, MAX (foo_date)) AS max_year,
DATEPART(yy, MIN (foo_date)) AS min_year
FROM Foobar;
It is important not to put the DATEPART() inside the aggregate
functions. It is easy to find the min and max on a column via indexes
or statistics tables. Once you put a funciton inside an aggregate
function, you cannot use these tools and have to do a table scan.
[Back to original message]
|