INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Extracting and sorting records by year query

Extracting and sorting records by year query

(OP)
I have an Access 2010 database in which I am having issues to isolate the text date from the string and sort the records by the text date.

Table: Movie
Column: Title
Data type: Text

Sample table data:
12 Years A Slave (2013-R)
127 Hours (2010-R)
17 Again (2009-PG13)
21 (2008-PG13)
27 Dresses (2011-PG13)

Here is the query I am working with:
SELECT Movie.Title AS movieyear, movie.title
FROM Movie
WHERE (((movie.title) Like '*20##*'))
ORDER BY movieyear, desc;

The query results I would like to see:
12 Years A Slave (2013-R)
27 Dresses (2011-PG13)
127 Hours (2010-R)
17 Again (2009-PG13)
21 (2008-PG13)

RE: Extracting and sorting records by year query

If your data is always as it appears in your samples, I would create a query that creates a Year column:

CODE --> SQL

SELECT Movie.*, Mid([Title],InStr([Title],"(")+1,4) AS [Year]
FROM Movie; 

You can then filter and/or sort the query by the Year column.

Duane
Hook'D on Access
MS Access MVP

RE: Extracting and sorting records by year query

You might also consider expanding Duane's query to extract the rating and then incorporating that into a query intended to normalize your data. One column/field each for title, year, rating, etc. Losing the parens.

Would make things easier to work with.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close