11. november 2005 - 00:20Der er
8 kommentarer og 1 løsning
Values from 2 tables that has no relation.
I have a report that shows result from a query on a table A. Now I also want a summary of values from table B in the report. There is no relation between the two tables. I need to have a query on table B to get the values. If I just add table B in the present query and give the parameters for the wanted values, all values from table A will be multiplyed by the number of found records in table B. What is the right way to do this?
As You can se below there are in fact 4 tables involved. It seems to work as it is, but how should it be written using union? SELECT Ftg.Ftg, Ftg.Orgnr, Grund.Regnr, Grund.Taxinr, Grund.SlutDag, Grund.Inkort, Grund.Kredit, Grund.Kontant, Grund.Budkorning, Grund.Bom, Konton.Kassa, Konton.Kred, Konton.Fsg25, Konton.Utgmoms25, Konton.Fsg6, Konton.Utgmoms6, Konton.Ingmoms, Konton.Kundforl, Sum(Resapost.DEBITERAS) AS Debiteras FROM Ftg, Konton, Grund, Resapost WHERE (((Resapost.Avr)=2) AND ((Grund.SlutDag) Between [Forms]![URVAL]![Startdatum] And [Forms]![URVAL]![Slutdatum]) AND ((Resapost.BokfMak) Between [Forms]![URVAL]![Startdatum] And [Forms]![URVAL]![Slutdatum])) GROUP BY Ftg.Ftg, Ftg.Orgnr, Grund.Regnr, Grund.Taxinr, Grund.SlutDag, Grund.Inkort, Grund.Kredit, Grund.Kontant, Grund.Budkorning, Grund.Bom, Konton.Kassa, Konton.Kred, Konton.Fsg25, Konton.Utgmoms25, Konton.Fsg6, Konton.Utgmoms6, Konton.Ingmoms, Konton.Kundforl;
we dont know enough about your tables and your requirement to give a solution.
If there is no relationship between the tables then you are going to end up with lots of information (records) which you dont infact want to see.
So you need to give more information to the data in the tables and to what you want to see, otherwise we will be just guessing and that can end up taking a long time.
See the sql above 11:54. The report is showing sales per taxicar during the period set out in the criteria and also the different accountnbrs and amount for the bookkeeping. From the table Ftg comes the firms name(Ftg) and the firms organisationnbr(Orgnr). From the table Konton comes accountnbrs for(Kassa, Kred, Fsg25, Utgmoms25, Fsg6,Utgmoms6, Ingmoms and Kundforl. From the table Grund comes Taxinbr(Taxinr) and Registrationnbr(Regnr)of the cars and enddate(SlutDat) of each drivers duty. There are approximately 60 dutys per car and month. From this table comes then also total income(Inkort), sales made on credit thereof(Kredit), cash sale(Kontant) and also amounts from(Budkorning and Bom)
Now I want to add losses from previus sales on credit and I'm getting those from the table Resapost which holds info about each and every reciept. When a loss is confirmed the todays date is set in the field BokfMak and the value 2 is set in field Avr. For every month, when the report is made, it shows total sales and also confirmed losses from previous sales. The report is opened from a form but has the instruction to open form URVAL on start where criterias are made(Date, all or single car, all or single driver) Then URVAL is hidden and the report shows the result.
I found my sollution. I simply made a ny query that finds the total amount in the field DEBITERAS, using the Nz function, from the table Resapost that meets the criteria set out in form URVAL. Instead of including the table Resapost in my report, I included the result from the new query. Now it works.
I'm cloosing this question. Thank You for Your time in this matter.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.