Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8578059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:18:03+00:00 2026-06-11T20:18:03+00:00

I have a Datatable with several hundred rows for this year in it. (MS

  • 0

I have a Datatable with several hundred rows for this year in it. (MS SqlServer 2k8)

I would like to split this data set out into customer enquiries / Month.

What I have so far is;

Select count(id) As Customers, DatePart(month, enquiryDate) as MonthTotal, productCode From customerEnquiries
where enquiryDate > '2012-01-01 00:00:00'
group by productCode, enquiryDate

But this then produces a row for each data item. (Whereas I want a row per month for each data item.)

So how do I change the above query, so that instead of getting

1 1 10
1 1 10
1 1 11
1 2 10
1 2 10

…

I get

2 1 10    <-- 2 enquiries for product code 10 in month 1
1 1 11    <-- 1 enquiries for product code 11 in month 1
2 2 10    <-- 2 enquiries for product code 10 in month 2
etc

And as a bonus question, is there an easy way of naming each month so the output is Jan, Feb, March instead of 1,2,3 in the month column?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:18:05+00:00Added an answer on June 11, 2026 at 8:18 pm

    Try this

    Select count(id) As Customers, DatePart(month, enquiryDate) as MonthTotal, productCode From customerEnquiries
    where enquiryDate > '2012-01-01 00:00:00'
    group by productCode, DatePart(month, enquiryDate)
    

    This may help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataTable that has several DataColumns and DataRow. Now i would like
I have a DataTable which I select from database (Well, these data cross several
I have datatable with column name tag and 100 rows of data.I need to
I have a Datatable in my C# program that I would like to INSERT
I would like to display the contents of a DataTable, divided into several groups
i have System.Data.DataRows with several fields, most of them just plain types like int,
I have a DataTable MyDT like below: string MyConString = SERVER= + sConfig_hostname +
I have a datatable which contains yearly data saved. e.g. dtDate Value 2010-01-01 00:00:00.000
I have this datatable, actually a list of datatable List<DataTable> lstDataSource , now for
I have a datatable in Gridview1 and have formatted it by adding several new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.