Hi everyone can someone explain to me in english what the following sql is doing step by step:
SELECT OD.OrderDetailID, OD.OrderID, OD.OrderDate, nz([orderdate]-(SELECT max(OrderDate) FROM tblOrderDetails
WHERE OrderID=OD.OrderID and OrderDetailID < OD.OrderDetailID),0) AS DaysBetween
FROM tblOrderDetails AS OD;
I am using this as a base for a calculated field I am creating in my database. However, the results returned are not always correct. I am hoping that if I can understand what the above sql is doing, I can figure out how to fix my problem. Below is an sql view of what I have created. What is in bold is based on the above sql.
SELECT Project.PrjtID, Project.ProjectName, CityFunds.TypeFundID, ProjectActualsProjections.FYDate, Project.LoanNo, CityFunds.AmtReg, CityFunds.LoanType
FROM Project INNER JOIN (ProjectActualsProjections INNER JOIN CityFunds ON ProjectActualsProjections.FYID = CityFunds.FYID) ON Project.PrjtID = ProjectActualsProjections.PrjtID
ORDER BY Project.ProjectName, CityFunds.TypeFundID, ProjectActualsProjections.FYDate DESC;
SELECT LA.PrjtID, LA.TypeFundID, LA.ProjectName, LA.LoanNo, LA.LoanType, LA.AmtReg, LA.FYDate, CCur(nz([AmtReg]-(SELECT max(AmtReg) FROM LoanAmounts
WHERE TypeFundID=LA.TypeFundID and PrjtID=LA.PrjtID and LoanType=LA.LoanType and FYDate < LA.FYDate),0)) AS RunningBalance
FROM LoanAmounts AS LA;
This is my fisrt attempt a using sql and I want to start using it more frequently. Thanks in advance.
SELECT OD.OrderDetailID, OD.OrderID, OD.OrderDate, nz([orderdate]-(SELECT max(OrderDate) FROM tblOrderDetails
WHERE OrderID=OD.OrderID and OrderDetailID < OD.OrderDetailID),0) AS DaysBetween
FROM tblOrderDetails AS OD;
I am using this as a base for a calculated field I am creating in my database. However, the results returned are not always correct. I am hoping that if I can understand what the above sql is doing, I can figure out how to fix my problem. Below is an sql view of what I have created. What is in bold is based on the above sql.
SELECT Project.PrjtID, Project.ProjectName, CityFunds.TypeFundID, ProjectActualsProjections.FYDate, Project.LoanNo, CityFunds.AmtReg, CityFunds.LoanType
FROM Project INNER JOIN (ProjectActualsProjections INNER JOIN CityFunds ON ProjectActualsProjections.FYID = CityFunds.FYID) ON Project.PrjtID = ProjectActualsProjections.PrjtID
ORDER BY Project.ProjectName, CityFunds.TypeFundID, ProjectActualsProjections.FYDate DESC;
SELECT LA.PrjtID, LA.TypeFundID, LA.ProjectName, LA.LoanNo, LA.LoanType, LA.AmtReg, LA.FYDate, CCur(nz([AmtReg]-(SELECT max(AmtReg) FROM LoanAmounts
WHERE TypeFundID=LA.TypeFundID and PrjtID=LA.PrjtID and LoanType=LA.LoanType and FYDate < LA.FYDate),0)) AS RunningBalance
FROM LoanAmounts AS LA;
This is my fisrt attempt a using sql and I want to start using it more frequently. Thanks in advance.
