Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query for Totals from 2 Tables

Author  Topic 

Shannon Sears
Starting Member

1 Post

Posted - 2009-11-28 : 16:44:12
I need a query to generate a list with the following fields:
Itemcode, Sum(Order.Rowtotal), Sum(Ship.Rowtotal) for the Period > '20091101' And < '20091130' And where Orderstatus = 'C'

From Order Table:
Order.id, Order.Itemcode, Order.Rowtotal, Order.Date, Order.Status

From Ship Table:
Ship.Id, Ship.Baseid (same as Order.id), Ship.Itemcode, Ship.Rowtotal, Ship.Date

Order table includes all orders.
Ship Table only includes records for items that have shipped.

Any help would be appreciated.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-28 : 17:06:05
Show us what you have so far, and we'll help fix it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-11-29 : 12:48:26
just do a LEFT JOIN with ship table and group on Itemcode and apply sum over required fields.
Go to Top of Page
   

- Advertisement -