简体   繁体   中英

SQL Server 2005 SUM

Hey all, this is my query string here:

 SELECT SUM(Total) as Total, AdministratorCode, SUM(WOD.Quantity) as thePass 
 FROM   tblWO as WO, 
        tblWOD as WOD
 WHERE WOD.OrderID = WO.ID 
 AND WO.OrderDate BETWEEN '2010-01-01' AND '2010-08-31' 
 AND Approved = '1' 
 ORDER BY WO.AdministratorCode

But i keep getting the error:

The multi-part identifier "tblWOD.Quantity" could not be bound.

Any help would be great!

Thanks,

David

SOLVED!!!

You need to use SUM(WOD.Quantiy) (or maybe Quanti t y unless the column name is missing a t )

You have aliased the table here tblWOD as WOD so you have no table with the exposed correlation name tblWOD

In your Select clause, use just: SUM(Quantiy) rather than SUM(tblWOD.Quantiy) . SUM(WOD.Quantiy) should also work

I believe you might need something like this

SELECT
    SUM(Total) as Total,
    WO.AdministratorCode,
    SUM(WOD.Quantity) as thePass
FROM tblWO as WO, tblWOD as WOD
WHERE
    WOD.OrderID = WO.ID
    AND WO.OrderDate BETWEEN '2010-01-01' AND '2010-08-31'
    AND [TableReference].Approved = '1'
Group By WO.AdministratorCode
ORDER BY WO.AdministratorCode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM