Avatar billede nyholm Novice
11. november 2005 - 00:20 Der 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?
Avatar billede Slettet bruger
11. november 2005 - 05:47 #1
If the information i the to tables are similar you could use a union like:

select column1, column2 from tabel a where some-condition
union
select column1, column2 from tabel b where some-condition

The requirement for the above is that the columns in the select are of similar types.
Avatar billede terry Ekspert
11. november 2005 - 09:57 #2
and it may be an idea to use

UNION ALL

if you want all records from both tables. otherwise duplicates are not included
Avatar billede nyholm Novice
11. november 2005 - 11:54 #3
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;
Avatar billede nyholm Novice
11. november 2005 - 13:03 #4
Well, I thought it worked but it does'nt. It only works if there are dates in Resapost.BokfMak that matches the criteria.
Avatar billede terry Ekspert
11. november 2005 - 19:59 #5
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.
Avatar billede nyholm Novice
11. november 2005 - 21:33 #6
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.
Avatar billede nyholm Novice
11. november 2005 - 21:37 #7
One correction. In this case only period of time is set by the form URVAL.
Avatar billede nyholm Novice
12. november 2005 - 08:56 #8
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.
Avatar billede nyholm Novice
12. november 2005 - 09:01 #9
I'm cloosing this question. Thank You for Your time in this matter.
Avatar billede Ny bruger Nybegynder

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.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester