TABLE Joins Problem
- From: "Jan S via SQLMonster.com" <forum@xxxxxxxxxxxxxx>
- Date: Thu, 11 Aug 2005 02:42:57 GMT
I have two sets of Data. For example Sales And Purchasing.
SALES(ISAL)
PURCHASING(IPUR)
-------------------------------
------------------------------------
ItemGroup
ItemGroup
ItemCode
ItemCode
DocDate
DocDate
Quantity
Quantity
Total
Total
The data mentioned above are all different with varying no. of rows in each
I need to do a join of the table just to show a simple summary by Item Group
For Example:
ItemGroup Total Sales Sold Qty Total Purchases
Purchased Qty
-------------- ------------------ ----------- -------
--------------- ---------------------
ACN 23432.90 234 1243.90
89
Etc.....
I am able to use the SUM Function for each table separately but when i join
the two, the values get all messed up. There is also a Master Table IGRP
which stores all the groups. There is also user variables
used to allow the user to specify the range of dates(but lets ignore that for
now).
What i tried:
SELECT T2.ItemGroup, SUM(T0.Total) as 'Total Purchases', SUM(T0.Quantity) as
'Purchased Qty', SUM(T1.Total) as 'Total Sales', SUM(T1.Quantity) as 'Sold
Qty' FROM IPUR T0 FULL OUTER JOIN ISAL T1 ON V1.ItemCode = V0.ItemCode INNER
JOIN IGRP ON T2.ItemGroup = T0.ItemGroup OR T2.ItemGroup = T1.ItemGroup GROUP
BY T3.ItemGroup
The resultset returned is correct for some entries but 2-5x higher for most.
Please help...Is there a way or do i just have to seperate both of them?
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-mseq/200508/1
.
- Follow-Ups:
- Re: TABLE Joins Problem
- From: Jan S via SQLMonster.com
- Re: TABLE Joins Problem
- Prev by Date: Re: Extracting Latest Date
- Next by Date: Re: TABLE Joins Problem
- Previous by thread: EXEC (select... ) problem Help!
- Next by thread: Re: TABLE Joins Problem
- Index(es):