SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get data from 2 tables in that way i need
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ksemaska
Starting Member

1 Posts

Posted - 04/23/2013 :  13:29:13  Show Profile  Reply with Quote
Hello proffesionals!

This what i got like 2 tables(1 is money income 2nd is money outcome) almost with same column names like

id name user_id catalogue sum date(timestamp)

This what i need:
i need get data from both tables, then count SUM(sum) from both as one, but this is a bit hard because 2nd table sum values should be negative then SUM is counted. Also each SUM value should be counted for each day where we have any income,outcome (or just one of these) something like GROUP BY CAST(`data`AS DATE). Any ideas? Thanks for replies! :)

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 04/23/2013 :  13:43:08  Show Profile  Reply with Quote

select dateadd(dd,datediff(dd,0,[date]),0), SUM([sum]) AS Total
FROM
(
SELECT *
FROM table1
UNION ALL
SELECT *
FROM table2
)t
GROUP BY dateadd(dd,datediff(dd,0,[date]),0)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000