[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • 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
Phil Chapman
Phil Chapman
1 Solution
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
Phil ChapmanAuthor Commented:


Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

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