Question

So I'm making a database for a school project regarding Movies / Actors (2 different tables). In the Microsoft Access database one of the field's type is Date/Time and I want to create a select query that will return me all movies from the year given for example:

public static DataSet GetByYear(string actorYear)

It needs to like something like this:

string sQuery = SELECT * FROM ActorsTable WHERE ActorsTable.actorDate.Year = actorYear

Something like that +- Also, can anyone please show me how can I make a select that will return me all actors (select * from ...) but sorted by their age?

Was it helpful?

Solution

Query based on the year of a date:

SELECT * 
FROM ActorsTable 
WHERE YEAR(actorDate) = actorYear

Actors ordered by age:

SELECT * FROM 
(
  SELECT a.*, DateDiff('yyyy', a.ActorDate, Now()) + 
              Int(Format(Now(), 'mmdd') < Format(a.ActorDate, 'mmdd')) 
              AS AgeOfActor
  FROM ActorsTable AS a
) AS m
ORDER BY m.AgeOfActor
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top