Mister_joe
02-01-2017, 07:28 AM
Greetings to everyone on this forum. I was reading an Access VBA book and I came upon the following block of code:
TRANSFORM Sum(CCur([Order Details].[Unit Price]*[Quantity]*(1-[Discount])/100)*100) AS [Product Amount]
SELECT Products.[Product Name], Orders.[Customer ID], Year([Order Date]) AS [Order Year]
FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.[Order ID] = [Order Details].[Order ID]) ON Products.ID = [Order Details].[Product ID]
WHERE (((Orders.[Order Date]) Between #1/1/1997# And #12/31/1997#))
GROUP BY Products.[Product Name], Orders.[Customer ID], Year([Order Date])
PIVOT "Qtr " & DatePart("q",[Order Date],1,0) IN ("Qtr 1","Qtr 2","Qtr 3","Qtr 4");
I am simply confused about the ordering of the keywords. I am equally confused about the relationship between the TRANSFORM statement and the PIVOT statement. Please, people, between the TRANSFORM statement, the SELECT statement, the GROUP BY clause and the PIVOT statement, what is the order of execution?
Also, what exactly does the TRANSFORM statement do?
You won't believe how many days I have spent trying to understand this block of codes. I will really appreciate it if someone can give me a link to a resource that explains the inner working of the PIVOT statement and the TRANSFORM statement.
Thanks for your assistance.
Joe
TRANSFORM Sum(CCur([Order Details].[Unit Price]*[Quantity]*(1-[Discount])/100)*100) AS [Product Amount]
SELECT Products.[Product Name], Orders.[Customer ID], Year([Order Date]) AS [Order Year]
FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.[Order ID] = [Order Details].[Order ID]) ON Products.ID = [Order Details].[Product ID]
WHERE (((Orders.[Order Date]) Between #1/1/1997# And #12/31/1997#))
GROUP BY Products.[Product Name], Orders.[Customer ID], Year([Order Date])
PIVOT "Qtr " & DatePart("q",[Order Date],1,0) IN ("Qtr 1","Qtr 2","Qtr 3","Qtr 4");
I am simply confused about the ordering of the keywords. I am equally confused about the relationship between the TRANSFORM statement and the PIVOT statement. Please, people, between the TRANSFORM statement, the SELECT statement, the GROUP BY clause and the PIVOT statement, what is the order of execution?
Also, what exactly does the TRANSFORM statement do?
You won't believe how many days I have spent trying to understand this block of codes. I will really appreciate it if someone can give me a link to a resource that explains the inner working of the PIVOT statement and the TRANSFORM statement.
Thanks for your assistance.
Joe