Tim
Mon Oct 10 10:54:38 CDT 2005
Thanks, Leonid, but this does not work either.
Cindy has put her finger on it - what I want cannot be done from the
present related tables.
The only solution seems to be to duplicate a few fields from child
tables into tenants which I know is not good practice. Then I can show
what I want without having the join to lettings which is the cause of
the problem when one tenant has multiple lettings. It works like a charm
for the simple case of a tenant having a single letting.
Tim
In article <#tm01CNzFHA.1264@tk2msftngp13.phx.gbl>, Leonid
<leonid@NOgradaSPAM.lv> writes
>It's hard to verify it without your data, but may be this will give you
>better result:
>
>SELECT tenants.tenantref,tenants.lastname,blocks.blockname,
>units.garnum,owners.owner;
>FROM garages!tenants;
> INNER JOIN garages!lettings ON Tenants.tenantref
>=Lettings.tenantref;
> .AND. Lettings.current = .T.;
> INNER JOIN garages!units ON Lettings.unitref = Units.unitref;
> INNER JOIN garages!blocks ON units.blockref=blocks.blockref ;
> .AND. blocks.blockname='Blendon Road';
> INNER JOIN garages!owners ON Blocks.ownerref =owners.ownerref;
> .AND. owners.lastname='Hicks';
> ORDER BY blocks.blockname,units.garnum;
> into cursor tempsql
>
>Leonid
>
>
>"Tim Hobson" <Tim@tjhobson.demon.co.uk> wrote in message
>news:Q5vhYbC2k$RDFwOx@tjhobson.demon.co.uk...
>> Thanks, Cindy.
>>
>> I have printed out your reference, which seems to use CREATE CURSOR
>> without SQL. In my case it would probably mean scanning 6 tables to get
>> the relationships right. I have not tried it yet because of the number
>> of tables involved.
>>
>> To explain the problem more thoroughly. The following code is OK and
>> will give me 3 results, one for each of the three lettings in the name
>> of Hicks and including the correct blocknames, garnums, and owners.
>>
>> SELECT tenants.tenantref,tenants.lastname,blocks.blockname,
>> units.garnum,owners.owner;
>> FROM garages!tenants;
>> INNER JOIN garages!lettings ON Tenants.tenantref =
>> Lettings.tenantref;
>> INNER JOIN garages!units ON Lettings.unitref = Units.unitref
>> ;
>> INNER JOIN garages!blocks ON units.blockref
>> =blocks.blockref ;
>> INNER JOIN garages!owners ON Blocks.ownerref =owners.ownerref;
>> WHERE Lettings.current = .T.;
>> .AND. blockname='Blendon Road';
>> .AND. lastname='Hicks';
>> ORDER BY blocks.blockname,units.garnum;
>> into cursor tempsql
>> browse
>>
>> Tenacc for Hicks contains 3 debit entries each month (what he owes for
>> each letting) and one credit entry for his combined payment. It is
>> related to tenants on tenantref.
>>
>> I now want to add tenacc debits and credits and try the following:
>>
>> SELECT tenants.tenantref,tenants.lastname,blocks.blockname;
>> units.garnum,owners.owner,tenacc.debit,tenacc.credit,tenacc.date;
>> FROM garages!tenants;
>> INNER JOIN garages!tenacc ON garages.tenantref =
>> tenacc.tenantref;
>> INNER JOIN garages!lettings ON Tenants.tenantref =
>> Lettings.tenantref;
>> INNER JOIN garages!units ON Lettings.unitref = Units.unitref
>> ;
>> INNER JOIN garages!blocks ON units.blockref
>> =blocks.blockref ;
>> INNER JOIN garages!owners ON Blocks.ownerref =owners.ownerref;
>> WHERE Lettings.current = .T.;
>> .AND. blockname='Blendon Road';
>> .AND. lastname='Hicks';
>> ORDER BY blocks.blockname,units.garnum,tenacc.date;
>> into cursor tempsql
>> browse
>>
>> The result duplicates all the debits and credits against each letting
>> instead of just showing them against each tenant, in this case three
>> times. I have to go via the relationships from tenants to owners in
>> order to get blockname, garnum, and owner. Otherwise a simple join of
>> tenants and tenacc would do the job.
>>
>> Could I create a SQL cursor as in the first coding above, and then join
>> that cursor in some way to tenacc ? I have considered doing it like that
>> through a temporary table instead of a cursor, which I could delete at
>> the end.
>>
>> Sorry to make this sound so complicated, but I am a bit desperate as I
>> need to be able to print it all out to produce the necessary accounting
>> data. Once I have the correct SQL data I will put it into a report.
>>
>> Tim
>>
>>
>> In article <eCv2PG4yFHA.2652@TK2MSFTNGP14.phx.gbl>, Cindy Winegarden
>> <cindy_winegarden@msn.com> writes
>>>Hi Tim,
>>>
>>>You haven't said what's wrong with your result, but what you're asking for
>>>is like an Access subreport. To do a subreport in VFP6 use the technique
>>>outlined at
http://fox.wikis.com/wc.dll?Wiki~MultiChildFoxProReports.
>>>
>>>
>>
>> --
>> Tim Hobson
>
>
--
Tim Hobson