Home Forums SQL Server 7,2000 SQL Server Newbies attempting to recreate complex "multi-layer" Access queries in SSMS RE: attempting to recreate complex "multi-layer" Access queries in SSMS

  • So here’s an example. The query works - to derive the business logic I need for the result the query is referring to aggregations or results in two other queries. It may be a crude, but it works. I know there’s as better way, what I’d like to know how you approach queries like this, where you have to refer to other aggregations or results for the ultimate result? Is it just in parenthesis in the main query itself? So a very long query?

    SELECT tlkpCompany.companyName, tblCycleRanch.hoops, tblCycleRanch.ranchNumber, tbNHC.[00002], tbNHC.[30], tbNHC.[40], tbNHC.[60], Sum(qry_13winterPlant.qtyReceived) AS SumOfqtyReceived, ([30]+[40]+(0.6*[60]))/([SumOfqtyReceived]/[TotalAc]) AS crateHC, qry_strawRanchTotAc.SumOfacres AS TotalAC, tbNHC.Date

    FROM (((tlkpCompany INNER JOIN tblCycleRanch ON tlkpCompany.[companyNum] = tblCycleRanch.[companyNum]) INNER JOIN qry_13winterPlant ON tblCycleRanch.ranchNumber = qry_13winterPlant.ranchNumber) INNER JOIN qry_strawRanchTotAc ON tblCycleRanch.ranchNumber = qry_strawRanchTotAc.ranchNumber) INNER JOIN tbNHC ON tblCycleRanch.ranchNumber = tbNHC.ranchNumber

    GROUP BY tlkpCompany.companyName, tblCycleRanch.hoops, tblCycleRanch.ranchNumber, tbNHC.[00002], tbNHC.[30], tbNHC.[40], tbNHC.[60], ([30]+[40]+(0.6*[60]))/([SumOfqtyReceived]/[TotalAc]), qry_strawRanchTotAc.SumOfacres, tbNHC.Date;

    _____________________________________________________________________
    As soon as you see something, you already start to intellectualize it. As soon as you intellectualize something, it is no longer what you saw. Suzuki-roshi