get year in a sql query

  • Thread starter Christopher Jursa
  • Start date
C

Christopher Jursa

Hello,

I have the following query. It selects a degree, salary range and
graduation date and sums the count of those combination of values as a
group.

SELECT D.degree, E.salaryRange, P.gradDate, COUNT(P.degree) AS [Count]
FROM person AS P, degree AS D, employment AS E
WHERE P.degree=D.degreeID And P.personID=E.personID
GROUP BY D.degree, E.salaryRange, P.gradDate;

P.gradDate is a month, year format field. How do I obtain the year so that
I may group by the year in my group by statement?

Cheers,

Chris
 
C

Chaim

Chris,

I'm not sure what you mean by 'month, year format', but if the field is a
datetime you can use DatePart (<part of date>, <date>). For the year from a
date you would use something like:

DatePart ("yyyy", P.gradDate) for a four digit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top