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

  • Home
  • SEARCH
  • 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 110443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:13:40+00:00 2026-05-11T02:13:40+00:00

I have a temp table I am creating a query off of in the

  • 0

I have a temp table I am creating a query off of in the following format. That contains a record for every CustomerID, Year, and Month for several years.

#T

Customer | CustomerID | Year | Month

ex.

Foo | 12345 | 2008 | 12   Foo | 12345 | 2008 | 11   Bar | 11224 | 2007 | 7 

When I join this temp table to another table of the following format I get many more results than I am expecting.

Event

EventID | CustomerID | DateOpened

ex.

1100 | 12345 | '2008-12-11 10:15:43' 1100 | 12345 | '2008-12-11 11:25:17' 

I am trying to get a result set of the count of events along with the Customer, Year, and Month like this.

SELECT COUNT(EventID), Customer, Year, Month FROM [Event]  JOIN #T ON [Event].CustomerID = #T.CustomerID WHERE [Event].DateOpened BETWEEN '2008-12-01' AND '2008-12-31' GROUP BY Customer, Year, Month ORDER BY Year, Month 

I am getting a record for every Year and Month instead of only for December 2008.

  • 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. 2026-05-11T02:13:41+00:00Added an answer on May 11, 2026 at 2:13 am

    You’re specifying the date on the event table but not on the join — so it’s joining all records from the temp table with a matching customerid.

    Try this:

    SELECT COUNT(e.EventID), T.Customer, T.Year, T.Month FROM [Event] e INNER JOIN #T T ON (   T.CustomerID = e.CustomerID and    T.Year = year(e.DateOpened) and    T.Month = month(e.DateOpened)    )  WHERE T.Year = 2008    and T.Month = 12  GROUP BY T.Customer, T.Year, T.Month ORDER BY T.Year, T.Month 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can certainly distribute an Erlang program across multiple cores… May 11, 2026 at 3:20 pm
  • added an answer Sure, the [::] is the extended slice operator. It allows… May 11, 2026 at 3:20 pm
  • added an answer This is possible if you're using Windows Authentication in your… May 11, 2026 at 3:20 pm

Related Questions

I have an Excel file that I need to process three times in integration
I wand to construct an MSI which, in its installation process, will deploy itself
I've currently got a database with about 20 reference tables, i.e. stuff like products,
I may be going about this backwards... I have a class which is like

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.