[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sums from Multiple Tables

Posted on 2005-04-21
7
Medium Priority
?
187 Views
Last Modified: 2010-03-19
I'm trying to sum a single column from multiple tables.  I then need to group them by a column that holds a date value.  How can I get a final sum for all the records in all the tables in one query?
0
Comment
Question by:thcit
  • 4
  • 3
7 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 375 total points
ID: 13837756
Since I don't have a DDL of your tables, your query may look like something like this:

SELECT DateColumn, SUM(YourColumn) AS YourColumn)
FROM (
SELECT DateColumn, SUM(YourColumn) AS YourColumn
FROM YourTable1
UNION ALL
SELECT DateColumn, SUM(YourColumn) AS YourColumn
FROM YourTable2
UNION ALL
SELECT DateColumn, SUM(YourColumn) AS YourColumn
FROM YourTable3) A
GROUP BY DateColumn

There are other options and we will only be able to help you if you provide the DDL of the tables.
0
 
LVL 3

Author Comment

by:thcit
ID: 13837827
What it a DDL and where do I get one?
0
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13837889
DDL stands for Data Definition Language.  In simple terms, I will be needing your table structures (CREATE TABLE).
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 3

Author Comment

by:thcit
ID: 13837980
Oh...never knew what that meant.

Here they are.

[x_date] char(8)
[x_adprice] char(7)


0
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13838004
These are the columns that exist in all your other tables?  How come x_adprice is char(7) and not a decimal/int/numeric value?
0
 
LVL 3

Author Comment

by:thcit
ID: 13838017
Worked!

Thanks rafrancisco
0
 
LVL 3

Author Comment

by:thcit
ID: 13838052
Yes and because the input control that I have to use from the software company will only stick char values in reliably.  So I just use SUM(convert(money,x_adprice)).
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

831 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