Question : SQL Query Problem

I have just been asked to create a spreadsheet based on material cost on items sold in the last month.

I have used the following code to collect the top level data but I am unable to progress further.
1:
2:
3:
4:
5:
6:
7:
SELECT     InvMovements.StockCode AS stockcode, InvMovements.TrnType AS TranType, InvMaster.ProductClass, InvMovements.TrnQty
FROM         InvMovements INNER JOIN
                      InvMaster ON InvMovements.StockCode = InvMaster.StockCode
GROUP BY InvMovements.StockCode, InvMovements.TrnType, InvMaster.ProductClass, InvMovements.TrnQty, InvMovements.EntryDate
HAVING      (InvMovements.TrnType = 'R') AND (InvMaster.ProductClass IN ('TM', 'PM', 'PDM', 'PRM')) AND (InvMovements.EntryDate <= CONVERT(DATETIME, 
                      '2010-05-31 00:00:00', 102)) AND (InvMovements.EntryDate >= CONVERT(DATETIME, '2010-05-01 00:00:00', 102))
ORDER BY InvMovements.StockCode

the code returns :
Stockcode QTY
xyz     1
xyz    56
abc    34
def     45
def     69

I need to group this to show
xyz    57
abc    34
def    114

Once I have the number of items I then need to check to bill of material table to extract the amount and cost of material used.  The problem I have is that part xyz might have a multiple level bill which I need to loop through. Part xyz might use 1 of tre and 2 of trd
parts tre and trd could be made up of other parts.
xyz
------tre   1
------trd   2

Part trd might be made up of
trd
------ ght   3
-------ghy  2

any help will be welcome

Answer : SQL Query Problem

typo there
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
SELECT  InvMovements.StockCode AS stockcode, 
	max(InvMovements.TrnType) AS TranType, 
	max(InvMaster.ProductClass), 
	sum(InvMovements.TrnQty) 
FROM         InvMovements 
INNER JOIN InvMaster ON InvMovements.StockCode = InvMaster.StockCode
where (InvMovements.TrnType = 'R') AND (InvMaster.ProductClass IN ('TM', 'PM', 'PDM', 'PRM')) AND (InvMovements.EntryDate <= CONVERT(DATETIME, 
                      '2010-05-31 00:00:00', 102)) AND (InvMovements.EntryDate >= CONVERT(DATETIME, '2010-05-01 00:00:00', 102))

GROUP BY InvMovements.StockCode

ORDER BY InvMovements.StockCode
Random Solutions  
 
programming4us programming4us