?
Solved

Merge 2 tables

Posted on 2009-04-27
4
Medium Priority
?
232 Views
Last Modified: 2012-05-06
I have two tables with common columns and need the sum of both (merged) for each day. How do I do that?

select * from EG3 where datediff(day,date,getdate()) = 0
select * from EG4 where datediff(day,date,getdate()) = 0
0
Comment
Question by:JessyRobinson1234
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:prachwal
ID: 24246097
select * from EG3 where datediff(day,date,getdate()) = 0
union
select * from EG4 where datediff(day,date,getdate()) = 0


or


select * from EG3 where datediff(day,date,getdate()) = 0
union all
select * from EG4 where datediff(day,date,getdate()) = 0
0
 

Author Comment

by:JessyRobinson1234
ID: 24246220
That returns 2 rows for today's date.  I want it to be the sum of the 2 records displayed in one row

select rack_capacity from EG3 where datediff(day,date,getdate()) = 0

union all

select capacity from EG4 where datediff(day,date,getdate()) = 0

retuns
81
56

desired outcome

137 (sum of both)
0
 
LVL 3

Accepted Solution

by:
prachwal earned 2000 total points
ID: 24246282
select sum (rack_capacity) as S from
(
select rack_capacity from EG3 where datediff(day,date,getdate()) = 0

union all

select capacity from EG4 where datediff(day,date,getdate()) = 0
) as T
0
 

Author Closing Comment

by:JessyRobinson1234
ID: 31575229
That's it. Great
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

850 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