I am working on a query to use for a cross tab for a ledger type report. There is a receipt file - receipts.dbf, a detail file - rcptinfo.dbf, and an account description file - accts.dbf. I want each of the accounts as column headings along with other receipt information with a row for each receipt. I will be using variables for the dates. The cross tab works great and gets exactly what I need from the data it receives. However, my problem is as follows:
The following query returns the result I need PLUS an extra record that contains nulls and zeroes as the first record.
SELECT receipts.rcptno, accts.shortname, rcptinfo.rcptamt, receipts.docket, receipts.spn, ;
receipts.payor, receipts.rcptdate, receipts.pmttype, receipts.rcpttype, receipts.amount ;
FROM receipts ;
JOIN rcptinfo ON receipts.rcptid = rcptinfo.rcptid ;
AND BETWEEN(receipts.rcptdate,{01/01/2009},{01/31/2009}) ;
RIGHT JOIN accts ON accts.acctno = rcptinfo.acctno ;
INTO CURSOR temp
DO vfpxtab WITH 'test',.t.,.t.,.t.,1,2,3,.t.,0,10
This next query returns the correct information, but only columns for accounts that have actual data, even though I used a left join.
SELECT accts.shortname, ;
receipts.rcptno, receipts.rcptdate, receipts.docket, receipts.spn, ;
receipts.rcpttype, receipts.pmttype, receipts.amount, receipts.payor, ;
rcptinfo.rcptamt ;
FROM accts ;
LEFT JOIN rcptinfo ON rcptinfo.acctno = accts.acctno ;
JOIN receipts ON receipts.rcptid = rcptinfo.rcptid ;
AND BETWEEN(receipts.rcptdate,{01/01/2009},{01/31/2009}) ;
INTO CURSOR tmp
DO vfpxtab WITH 'test',.t.,.t.,.t.,2,1,10,.t.,0,10
There are no null or empty records in any of the tables. Each receipt record has matching detail records. I tried == instead of == with no change in results. I'm sure I'm missing something simple. Can somebody else see it? I've been going around in circles for a while now.
The following query returns the result I need PLUS an extra record that contains nulls and zeroes as the first record.
SELECT receipts.rcptno, accts.shortname, rcptinfo.rcptamt, receipts.docket, receipts.spn, ;
receipts.payor, receipts.rcptdate, receipts.pmttype, receipts.rcpttype, receipts.amount ;
FROM receipts ;
JOIN rcptinfo ON receipts.rcptid = rcptinfo.rcptid ;
AND BETWEEN(receipts.rcptdate,{01/01/2009},{01/31/2009}) ;
RIGHT JOIN accts ON accts.acctno = rcptinfo.acctno ;
INTO CURSOR temp
DO vfpxtab WITH 'test',.t.,.t.,.t.,1,2,3,.t.,0,10
This next query returns the correct information, but only columns for accounts that have actual data, even though I used a left join.
SELECT accts.shortname, ;
receipts.rcptno, receipts.rcptdate, receipts.docket, receipts.spn, ;
receipts.rcpttype, receipts.pmttype, receipts.amount, receipts.payor, ;
rcptinfo.rcptamt ;
FROM accts ;
LEFT JOIN rcptinfo ON rcptinfo.acctno = accts.acctno ;
JOIN receipts ON receipts.rcptid = rcptinfo.rcptid ;
AND BETWEEN(receipts.rcptdate,{01/01/2009},{01/31/2009}) ;
INTO CURSOR tmp
DO vfpxtab WITH 'test',.t.,.t.,.t.,2,1,10,.t.,0,10
There are no null or empty records in any of the tables. Each receipt record has matching detail records. I tried == instead of == with no change in results. I'm sure I'm missing something simple. Can somebody else see it? I've been going around in circles for a while now.