SQL help using Group By

Steve Albin steve at steve-albin.com
Sun Apr 3 11:34:26 CDT 2011


I have the following SQL:

SELECT i.dInvoiceDate, i.nCollected, 
  i.dCollDate, i.cDescription, i.nid, billSum.tot_amt 
   FROM   Invoices i  inner join 
   	(SELECT sum(BillItems.nFixedCost) As tot_amt, j.nId As theId
		FROM	invoices j, Customers,BillItems, Lnk_InvTask
		where j.oCustPtr = Customers.RecID 
		and BillItems.RecID = Lnk_InvTask.taskPtr
		and Lnk_InvTask.invPtr = j.RecID 
		and Customers.nId = 14
		GROUP BY j.nId 
		) As billSum  on i.nid = billSum.theId
  ORDER BY i.dInvoiceDate
  
I am trying to list my invoices along with a total amount derived from the individual items in the invoice (BillItems).  These are linked to the invoices via the Lnk_InvTask table.

Every time I try to execute this SQL in VStudio, I get the following error:
	Kernel error: 0x51500. Identifier "billSum.theId" is not found.

The sub-query works fine on its own.

Any help will be appreciated.  

Thanks,

Steve

--
Steve Albin, Montclair, NJ
http://www.steve-albin.com
http://www.jazzdiscography.com



More information about the Valentina mailing list