I'm trying to transpose row to columns sequentially with SQL in MS ACCESS database . I have the SQL below, but it's not right yet: I want in one query. If there is an answer then I don't want to use the function in MS Access because I want to use the SQL for VB.Net. Please Guide Me.
Thanks
TRANSFORM Sum(Tableproduct.[Qty]) AS SumOfQty
SELECT Tableproduct.Codeproduct AS CodeProduct, Tableproduct.Colour AS Colour, Sum(Tableproduct.Qty) AS Total
FROM Tableproduct INNER JOIN SizeProduct ON Tableproduct.Size = SizeProduct.Size
WHERE Tableproduct.Codeproduct = 'A'
GROUP BY Tableproduct.Codeproduct, Tableproduct.Colour
PIVOT SizeProduct.Size;
Results from the above SQL code :
| CodeProduct | Colour | Total | L | M | S | XL |
|---|---|---|---|---|---|---|
| A | Black | 30 | 20 | 10 | ||
| A | White | 25 | 10 | 15 |
I want to add the SQL code below into one query
ORDER BY SizeProduct.Sequence ASC
Sample Data :
Table TableProduct
| CodeProduct | Colour | Size | Qty |
|---|---|---|---|
| A | Black | XL | 10 |
| A | White | S | 15 |
| A | Black | M | 20 |
| A | White | L | 10 |
Table Sizeproduct
| Sizeproduct | Sequence |
|---|---|
| S | 1 |
| M | 2 |
| L | 3 |
| XL | 4 |
Desired Result
| CodeProduct | Colour | S | M | L | XL | TOTAL |
|---|---|---|---|---|---|---|
| A | Black | 20 | 10 | 30 | ||
| A | White | 15 | 10 | 25 |
