TheOneRing
Programmer
Gedday,
I have the following SQL Statement:
SELECT tblCustomers.CompanyName AS Company, tblCustomers.CustomerID AS CustomerID, tblCustomers.TypeofCustomer, Count(*) AS Numcalls, Sum(tblInvoice.dblSubTotal) AS TotalDollars
FROM tblCustomers INNER JOIN tblInvoice ON (tblCustomers.CustomerID = tblInvoice.strShipTo) AND (tblCustomers.CustomerID = tblInvoice.strBillTo)
WHERE (((tblInvoice.dtmDate) Between CDate('01-03-02') And CDate('31-03-02')) AND ((tblInvoice.strType)<>'PB'))
GROUP BY tblCustomers.CompanyName, tblCustomers.TypeofCustomer,tblCustomers.CustomerID
now this works fine and returns the information that I want, but I want to be able to sort the records by the number of calls (NumCalls) or by the total dollars (TotalDollars) but when I put in ORDER BY Numcalls or ORDER BY TotalDollars, it doesn't work.
The only way I can think of doing it is by selecting the records into a temp table and then selecting them again and then sorting them.
Does anyone have any Ideas please.
I have the following SQL Statement:
SELECT tblCustomers.CompanyName AS Company, tblCustomers.CustomerID AS CustomerID, tblCustomers.TypeofCustomer, Count(*) AS Numcalls, Sum(tblInvoice.dblSubTotal) AS TotalDollars
FROM tblCustomers INNER JOIN tblInvoice ON (tblCustomers.CustomerID = tblInvoice.strShipTo) AND (tblCustomers.CustomerID = tblInvoice.strBillTo)
WHERE (((tblInvoice.dtmDate) Between CDate('01-03-02') And CDate('31-03-02')) AND ((tblInvoice.strType)<>'PB'))
GROUP BY tblCustomers.CompanyName, tblCustomers.TypeofCustomer,tblCustomers.CustomerID
now this works fine and returns the information that I want, but I want to be able to sort the records by the number of calls (NumCalls) or by the total dollars (TotalDollars) but when I put in ORDER BY Numcalls or ORDER BY TotalDollars, it doesn't work.
The only way I can think of doing it is by selecting the records into a temp table and then selecting them again and then sorting them.
Does anyone have any Ideas please.