I'm not exactly sure if what I'm needing is possible. I have two tables that are joined, one being a list of items, and one being when there was any movement for those items on specified date. The movements are specified by totalizers, in this example 1=Purchased, 2=Sold, 3=Adjusted. The coding I have so far gives me a separate row for each totalizer. I am needing to combine the rows into one for each item.
SELECT [Totalizer]=COALESCE(t2.[F1034],0)
,[UPC]=t1.[F01]
,[QTY]=sum(coalesce(t2.[F64],0))
,[Total Amount]=sum(COALESCE(t2.[F65],0))
FROM [STORESQL].[dbo].[COST_TAB] t1
LEFT OUTER JOIN [STORESQL].[dbo].[RPT_ITM_D] t2
ON t1.F01=t2.F01 AND (F254='2011-10-1') and (F1034=1 or F1034=2 or F1034=3)
group by t1.F01,F1034
order by t1.F01
COST_TAB table consists of:
UPC
1
2
3
4
RPT_ITM_D Consists of the item movement:
UPC Date Totalizer QTY Total Amount
1 2011-10-1 1 1 9.00
1 2011-10-1 2 1 9.99
2 2011-10-1 1 2 6.00
2 2011-10-1 2 1 3.99
2 2011-10-1 3 1 3.00
3 2011-10-1 1 1 1.00
The SQL Code I have now results in:
UPC Date Totalizer QTY Total Amount
1 2011-10-1 1 1 9.00
1 2011-10-1 2 1 9.99
2 2011-10-1 1 2 6.00
2 2011-10-1 2 1 3.99
2 2011-10-1 3 1 3.00
3 2011-10-1 1 1 1.00
4 2011-10-1 0 0 0.00
I am needing it to result in:
UPC Date Purchased AMT Sold AMT Adjusted AMT
1 2011-10-1 1 9.00 1 9.99 0 0.00
2 2011-10-1 2 6.00 1 3.99 1 3.00
3 2011-10-1 1 1.00 0 0.00 0 0.00
4 2011-10-1 0 0.00 0 0.00 0 0.00
I realize I will probably have to completely rework my columns, but I don't know where to start with this, or if I can even do it.