Select *
from dbo.SomeTable
Where Year(Date_Field) between 1993 and 1998
ASKER
ASKER
ASKER
ASKER
ASKER
SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.
TRUSTED BY
a. for EVERY ROW you are running a function (this consumes cpu), and, MORE IMPORTANTLY
b. using a function on the column date DISABLES any INDEX in query optimization on the column
i.e. it makes your query SLOWER than it should be
there is a simple saying: "don't use functions on data in the where clause"
This is what you asked for:
Select *
from dbo.SomeTable
Where EXTRACT (YEAR FROM Date_Field) between 1993 and 1998
But in truth the faster way is this:
Select *
from dbo.SomeTable
Where Date_Field >= '1993-01-01' and Date_Field < '1999-01-01'
Also note, between is just not good for date ranges, always use >= with < instead
see Beware of Between
Itzik Ben-Gan