StealthRT
StealthRT

Reputation: 10542

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!!!

Upvotes: 2

Views: 1040

Answers (3)

Sage
Sage

Reputation: 4937

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

Upvotes: 1

Patrick Karcher
Patrick Karcher

Reputation: 23603

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

Upvotes: 2

Martin Smith
Martin Smith

Reputation: 452978

You need to use SUM(WOD.Quantiy) (or maybe Quantity 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

Upvotes: 2

Related Questions