Rik_StHelens
Registered User.
- Local time
- Today, 15:42
- Joined
- Sep 15, 2009
- Messages
- 164
Hi
I have 3 queries which produce statements for customers/suppliers and anyone with an overdue balance
The customer/supplier statements work fine, and here is the sql:
SELECT STATMENT.CUSTOMER AS [Customer Code], STATMENT.LINEDATE AS [Invoice Date], STATMENT.REFERENCE AS [Tyrenet Invoice], STATMENT.ADVICE AS [Tyrenet Ref], STATMENT.COMMENT AS [Cust Order No], STATMENT.BATCHREF AS [Reg No], STATMENT.UNALLOC AS [Outstanding Bal], CUSTOMER.NAME, CUSTOMER.ADDR1, CUSTOMER.ADDR2, CUSTOMER.ADDR3, CUSTOMER.ADDR4, CUSTOMER.POSTCODE, CUSTOMER.BALANCE1, CUSTOMER.BALANCE2, CUSTOMER.BALANCE3, CUSTOMER.BALANCE4, CUSTOMER.BALANCE5, VANRUN.FAX
FROM (STATMENT INNER JOIN CUSTOMER ON STATMENT.CUSTOMER = CUSTOMER.CODE) INNER JOIN VANRUN ON CUSTOMER.CODE = VANRUN.CODE
GROUP BY STATMENT.CUSTOMER, STATMENT.LINEDATE, STATMENT.REFERENCE, STATMENT.ADVICE, STATMENT.COMMENT, STATMENT.BATCHREF, STATMENT.UNALLOC, CUSTOMER.NAME, CUSTOMER.ADDR1, CUSTOMER.ADDR2, CUSTOMER.ADDR3, CUSTOMER.ADDR4, CUSTOMER.POSTCODE, CUSTOMER.BALANCE1, CUSTOMER.BALANCE2, CUSTOMER.BALANCE3, CUSTOMER.BALANCE4, CUSTOMER.BALANCE5, VANRUN.FAX
HAVING (((STATMENT.CUSTOMER) Like "*" & [Enter Customer Code (For All Invoices Leave Blank ] & "*") AND ((STATMENT.UNALLOC)<>0))
ORDER BY STATMENT.LINEDATE;
However, the overdue balance statement will not take the value I pass in to it, and will give notices for all customers rather than a specific customer. For some reason when building the query it has added in a HAVING instead of a WHERE, as in the other queries.
SELECT STATMENT.CUSTOMER AS [Customer Code], STATMENT.LINEDATE AS [Invoice Date], STATMENT.REFERENCE AS [Tyrenet Invoice], STATMENT.ADVICE AS [Tyrenet Ref], STATMENT.COMMENT AS [Cust Order No], STATMENT.BATCHREF AS [Reg No], STATMENT.UNALLOC AS [Outstanding Bal], CUSTOMER.NAME, CUSTOMER.ADDR1, CUSTOMER.ADDR2, CUSTOMER.ADDR3, CUSTOMER.ADDR4, CUSTOMER.POSTCODE, CUSTOMER.BALANCE1, CUSTOMER.BALANCE2, CUSTOMER.BALANCE3, CUSTOMER.BALANCE4, CUSTOMER.BALANCE5, VANRUN.FAX
FROM VANRUN INNER JOIN (STATMENT INNER JOIN CUSTOMER ON STATMENT.CUSTOMER = CUSTOMER.CODE) ON VANRUN.CODE = CUSTOMER.CODE
GROUP BY STATMENT.CUSTOMER, STATMENT.LINEDATE, STATMENT.REFERENCE, STATMENT.ADVICE, STATMENT.COMMENT, STATMENT.BATCHREF, STATMENT.UNALLOC, CUSTOMER.NAME, CUSTOMER.ADDR1, CUSTOMER.ADDR2, CUSTOMER.ADDR3, CUSTOMER.ADDR4, CUSTOMER.POSTCODE, CUSTOMER.BALANCE1, CUSTOMER.BALANCE2, CUSTOMER.BALANCE3, CUSTOMER.BALANCE4, CUSTOMER.BALANCE5, VANRUN.FAX
HAVING (((STATMENT.CUSTOMER) Like "*" & [Enter Customer Code (For All Invoices Leave Blank ] & "*") AND ((STATMENT.UNALLOC)<>0)) OR (((CUSTOMER.BALANCE3)<>0)) OR (((CUSTOMER.BALANCE4)<>0)) OR (((CUSTOMER.BALANCE5)<>0))
ORDER BY STATMENT.LINEDATE;
If i change the HAVING to WHER i get a syntax error in the clause:
VANRUN.FAX
HAVING (((STATMENT.CUSTOMER) Like "*" & [Enter Customer Code (For All Invoices Leave Blank ] & "*") AND ((STATMENT.UNALLOC)<>0)) OR (((CUSTOMER.BALANCE3)<>0)) OR (((CUSTOMER.BALANCE4)<>0)) OR (((CUSTOMER.BALANCE5)<>0))
ORDER BY STATMENT.LINEDATE;
I am sure it is the having causing the problem, but how do i fix this?
Thanks in advance
I have 3 queries which produce statements for customers/suppliers and anyone with an overdue balance
The customer/supplier statements work fine, and here is the sql:
SELECT STATMENT.CUSTOMER AS [Customer Code], STATMENT.LINEDATE AS [Invoice Date], STATMENT.REFERENCE AS [Tyrenet Invoice], STATMENT.ADVICE AS [Tyrenet Ref], STATMENT.COMMENT AS [Cust Order No], STATMENT.BATCHREF AS [Reg No], STATMENT.UNALLOC AS [Outstanding Bal], CUSTOMER.NAME, CUSTOMER.ADDR1, CUSTOMER.ADDR2, CUSTOMER.ADDR3, CUSTOMER.ADDR4, CUSTOMER.POSTCODE, CUSTOMER.BALANCE1, CUSTOMER.BALANCE2, CUSTOMER.BALANCE3, CUSTOMER.BALANCE4, CUSTOMER.BALANCE5, VANRUN.FAX
FROM (STATMENT INNER JOIN CUSTOMER ON STATMENT.CUSTOMER = CUSTOMER.CODE) INNER JOIN VANRUN ON CUSTOMER.CODE = VANRUN.CODE
GROUP BY STATMENT.CUSTOMER, STATMENT.LINEDATE, STATMENT.REFERENCE, STATMENT.ADVICE, STATMENT.COMMENT, STATMENT.BATCHREF, STATMENT.UNALLOC, CUSTOMER.NAME, CUSTOMER.ADDR1, CUSTOMER.ADDR2, CUSTOMER.ADDR3, CUSTOMER.ADDR4, CUSTOMER.POSTCODE, CUSTOMER.BALANCE1, CUSTOMER.BALANCE2, CUSTOMER.BALANCE3, CUSTOMER.BALANCE4, CUSTOMER.BALANCE5, VANRUN.FAX
HAVING (((STATMENT.CUSTOMER) Like "*" & [Enter Customer Code (For All Invoices Leave Blank ] & "*") AND ((STATMENT.UNALLOC)<>0))
ORDER BY STATMENT.LINEDATE;
However, the overdue balance statement will not take the value I pass in to it, and will give notices for all customers rather than a specific customer. For some reason when building the query it has added in a HAVING instead of a WHERE, as in the other queries.
SELECT STATMENT.CUSTOMER AS [Customer Code], STATMENT.LINEDATE AS [Invoice Date], STATMENT.REFERENCE AS [Tyrenet Invoice], STATMENT.ADVICE AS [Tyrenet Ref], STATMENT.COMMENT AS [Cust Order No], STATMENT.BATCHREF AS [Reg No], STATMENT.UNALLOC AS [Outstanding Bal], CUSTOMER.NAME, CUSTOMER.ADDR1, CUSTOMER.ADDR2, CUSTOMER.ADDR3, CUSTOMER.ADDR4, CUSTOMER.POSTCODE, CUSTOMER.BALANCE1, CUSTOMER.BALANCE2, CUSTOMER.BALANCE3, CUSTOMER.BALANCE4, CUSTOMER.BALANCE5, VANRUN.FAX
FROM VANRUN INNER JOIN (STATMENT INNER JOIN CUSTOMER ON STATMENT.CUSTOMER = CUSTOMER.CODE) ON VANRUN.CODE = CUSTOMER.CODE
GROUP BY STATMENT.CUSTOMER, STATMENT.LINEDATE, STATMENT.REFERENCE, STATMENT.ADVICE, STATMENT.COMMENT, STATMENT.BATCHREF, STATMENT.UNALLOC, CUSTOMER.NAME, CUSTOMER.ADDR1, CUSTOMER.ADDR2, CUSTOMER.ADDR3, CUSTOMER.ADDR4, CUSTOMER.POSTCODE, CUSTOMER.BALANCE1, CUSTOMER.BALANCE2, CUSTOMER.BALANCE3, CUSTOMER.BALANCE4, CUSTOMER.BALANCE5, VANRUN.FAX
HAVING (((STATMENT.CUSTOMER) Like "*" & [Enter Customer Code (For All Invoices Leave Blank ] & "*") AND ((STATMENT.UNALLOC)<>0)) OR (((CUSTOMER.BALANCE3)<>0)) OR (((CUSTOMER.BALANCE4)<>0)) OR (((CUSTOMER.BALANCE5)<>0))
ORDER BY STATMENT.LINEDATE;
If i change the HAVING to WHER i get a syntax error in the clause:
VANRUN.FAX
HAVING (((STATMENT.CUSTOMER) Like "*" & [Enter Customer Code (For All Invoices Leave Blank ] & "*") AND ((STATMENT.UNALLOC)<>0)) OR (((CUSTOMER.BALANCE3)<>0)) OR (((CUSTOMER.BALANCE4)<>0)) OR (((CUSTOMER.BALANCE5)<>0))
ORDER BY STATMENT.LINEDATE;
I am sure it is the having causing the problem, but how do i fix this?
Thanks in advance