Sort by Year

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table called RELEASE in this table I have the three following
fields: 1.Date (Data Type Date/Time), 2.Customer (Data Type Text), 3. Serial
number (Data Type Text). I want to make a Query that will Query by year only.
I would like the Query to return all three fields. Would I enter code in the
SQL View window or would I do a Criteria Expression in Query design view?
What would the Code look like? In addition, does any one know of any links
that show Query design examples?
 
Dennis

Create a query that returns the three fields.

Add a new field, something like:

Expr1: Year([YourDateField])

Use the SortBy "cell" under this new field to select your sorting direction.

--
Regards

Jeff Boyce
Microsoft Office/Access MVP
Microsoft IT Academy Program Mentor
 
Hi Dennis,

The Year() Function extracts just the year from a date field. I also added a
parameter query so that you can just pick one year. In the QBE grid, you can
stop the Year from showing up by unchecking it.

You should be able to paste the stuff below into the SQL view of a query.

Oh! Date is a reserved word in Access. If you aren't careful, it can cause
problems when used as a field name or table name. Somethign like ReleaseDate
would be much better. Also not putting spaces or special characters, except
for underscores _ in field or table names is a real good thing in Access. I
had to put [] around Serial Number as it has a space in it.

PARAMETERS [Enter the Year] Short;
SELECT RELEASE.Date,
RELEASE.Customer,
RELEASE.[Serial Number],
Year([Date]) AS TheYear
FROM RELEASE
WHERE (((Year([Date]))=[Enter the Year]));
 
Back
Top