• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

Grouping Records By Year Query

The query below gives me the total accounts with the same submission date.  But  I need the total accounts with the same year only.

What needs to be changed in the query?


SubmissionDate is a DateTime datatype

SELECT count(account)as NumOfAccounts,SubmissionDate
FROM Accounts
Group By SubmissionDate HAVING count(account)> 0
0
Phil Chapman
Asked:
Phil Chapman
1 Solution
 
rajeevnandanmishraCommented:
Looks you will  get multiple years data , unless you want to parametrize the year part in the where clause.

try using this:
select count(account) as NumOfAccount, datepart(yy,SubmissionDate) nYear
from Accounts
Group by datepart(yy,SubmissionDate)
having count(account)>0

or you can add a where clause
where datepart(yy,SubmissionDate) = 2011
0
 
Phil ChapmanAuthor Commented:
Perfect!

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now