Solved

calculate sales based on specific dates in table in sql server 2000

Posted on 2011-02-16
2
348 Views
Last Modified: 2012-05-11
Hi all.

I have a SQL Server 2000 table (myTableA) that has the following fields: ContractNo, CustomerID, StartDate, EndDate

I have another table (myTableB)that stores every sales transaction for each customer. One of the fields in myTableB is InvoiceDate. I want to be able to sum up all the sales based on the InvoiceDate falling between the StartDate and EndDate for the customers' contractNo.

So for example, let's say I have in myTableA:

ContractA---Customer123---01/01/2010---03/01/2010
ContractB---Customer123---03/02/2010---12/31/2010

And in myTableB:
Customer123---InvoiceDate:02/01/2010---$5
Customer123---InvoiceDate:02/24/2010---$5
Customer123---InvoiceDate:03/05/2010---$20

I would like the end result to show:
ContractA---Customer123---$10
ContractB---Customer123---$20

How can I do this?

Thank you in advance!
0
Comment
Question by:printmedia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
JoeNuvo earned 500 total points
ID: 34907043
SELECT A.ContractNo, A.CustomerID, SUM(amount) AS Total
FROM myTableA A INNER JOIN myTableB B
	ON A.CustomerID = B.CustomerID 
AND B.InvoiceDate BETWEEN A.StartDate AND A.EndDate
GROUP BY A.ContractNo, A.CustomerID

Open in new window

0
 

Author Closing Comment

by:printmedia
ID: 34907160
Thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TSQL remove duplicates from different columns 14 52
Sub form showing data is being saved but cannot be displayed.. 31 69
Sorting a SQL script 5 41
SQL query 45 41
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question