Avatar billede maria.cand Nybegynder
29. september 2003 - 21:09 Der er 19 kommentarer og
1 løsning

Hjælp til, at samle alle data i en tabel

Jeg arbejder i en telemarketingsafdeling hvor vi har et system til at registere når vi ringer ud på de enkelte emner. Der er op til 8 mennesker på hver projekt og de har hver deres tabel, foresp. samt formular.De hedder feks. kunde 1, kunde 2, kunde 3 osv. Tabeller, forsp. og formularene er fuldstædig identisk blot med et andet navn. Nu vil jeg gerne samle daten fra de 3-8 tabeller i en er dette mulig og hvordan gør jeg...


Det må gerne være meget detaljeret beskrevet
Avatar billede terry Ekspert
29. september 2003 - 21:21 #1
maria>IF you have other related tables then this could be a problem with Primary/foreign keys. But if all your eggs are in one basket then you COULD try making a UNION query. This will show ALL records from the tables you include. Then you can make a new EMPTY table which has the same layout as the originals. Then you make an append query taking the result of your UNION query and appending it to your NEW table!
Avatar billede terry Ekspert
29. september 2003 - 21:21 #2
an example of a UNION query

SELECT * FROM [kunde 1]
UNION
SELECT * FROM [kunde 2]
UNION
.....
Avatar billede terry Ekspert
29. september 2003 - 21:23 #3
IF there are duplicate records which you want to include then you use

UNION ALL......
Avatar billede maria.cand Nybegynder
29. september 2003 - 21:26 #4
Men terry dataen skal stå under hinanden...og dehar alle den samme primære nøgle der hedder kontakt-id
Avatar billede terry Ekspert
29. september 2003 - 21:32 #5
when you say "stå under hinanden" a UNION join will show records under each other!

Do you use the primary key as a relationship to other tables? If you do NOT then you dont need to include this in the UNION select. Then when you append them to the new table all records will get a new primary key!

you now have to include the fields because you must NOT include kontakt-id!

SELECT fld1, fld2, fld3 ....... FROM [Kunde 1]
UNION
SELECT fld1, fld2, fld3 ....... FROM [Kunde 2]
UNION
.....
Avatar billede terry Ekspert
29. september 2003 - 21:33 #6
TRY making a UNION join with ALL fields just so you can see what it does!

You have to enter the SQL directly in SQL query window!
Avatar billede maria.cand Nybegynder
29. september 2003 - 21:38 #7
hmm jeg kan ikke få det til at virke i foresp. kommer det til, at stå hen af og der står

Firmanavn kunde 1, firmanavn kunde 2
Avatar billede terry Ekspert
29. september 2003 - 22:00 #8
you MUST NOT write kunde 1
Normally there should NOTbe spaces in the table names!
Write
[kunde 1]

For example>
SELECT Firmanavn FROM [kunde 1]
UNION
SELECT Firmanavn FROM [kunde 2]

You have to enter the SQL directly in the SQL view, you can not use the query designer when making UNION queries
Avatar billede terry Ekspert
29. september 2003 - 22:04 #9
If you right click on the are where you normally add your tables yiu get a menu where you can choose SQL specific and then UNION. If you select union you will now be in SQL view where you can directly enter the SQL for the union query
Avatar billede terry Ekspert
29. september 2003 - 22:07 #10
well I think that is me for the night :o)
Avatar billede maria.cand Nybegynder
29. september 2003 - 22:08 #11
Terry det virker med den kode du har skrevet her SELECT Firmanavn FROM [kunde 1]
UNION
SELECT Firmanavn FROM [kunde 2]

Men hvordan ser den øjagtig ud når det er alle data fra tabellerne!!
Avatar billede terry Ekspert
29. september 2003 - 22:13 #12
It looks the same as if you had selected all records from one table and then all records from another table on top of each other, not beside each other.

If there are 20 columns in the tables then there will be 20 columns in the result, ready to copy to your NEW table (with 21) columns. And if yiu are still awake NOTICE I write 21! the first column is your autonumber which you do NOT append to as this gets done automatically!
Avatar billede maria.cand Nybegynder
29. september 2003 - 22:20 #13
ok jeg har fundet ud af det - jeg er bare lidt små dum;-) - Jeg har lavet den både som en tilførelsesforsp. og som du beskrev.. Men med dit eks. ved jeg ikke helt hvordan jeg får dataen over i en ny tabel!!
Avatar billede maria.cand Nybegynder
29. september 2003 - 22:37 #14
Takker Terry, men jeg vil gerne hvis du kan beskrive hvordan jeg får dataen med over i en ny tabel
Avatar billede terry Ekspert
30. september 2003 - 09:46 #15
You now have a UNION query which selects records from all of your tables.
You should also have a new table with the same structure as your original tables.
Now make a new query and choose the UNION query as the source. (from the list of tables and queries).

Now you need to alter the query to an append query. In the menu there is a little arrow pointing down. You can choose the type of query here, choose append query, and then choose the table you want to append to.

Now using the mouse you mark ALL fields (not the *) in the table and drag them over to the rows and columns area of the query. You should now see that the row named "Field:" contains all of the row names from the table, and because the names of the fields in the new table are the same then the row named "Append To:" will have the same name.

Then save the query, and you are ready to try it :o)
Hope that helps.
Avatar billede terry Ekspert
30. september 2003 - 09:48 #16
records and then COMPACT the dB. When you compact the dB it also resets the autonumber fields to 0.
Avatar billede maria.cand Nybegynder
30. september 2003 - 15:41 #17
Terry hver gang jeg kører tilføjelsesforsp. så kopiere den de samme info ind - Er der evt. et alternativ??
Avatar billede terry Ekspert
30. september 2003 - 15:50 #18
Maria, what are you expecting it to do? This is what you asked for isnt it?
"Nu vil jeg gerne samle daten fra de 3-8 tabeller i en"
and once you have run the append query ONCE then it is done!!!!
Avatar billede maria.cand Nybegynder
08. oktober 2003 - 17:13 #19
Perfekt - Bare misforstået lidt
Avatar billede terry Ekspert
08. oktober 2003 - 18:42 #20
OK :o)
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