24. januar 2002 - 18:07Der er
5 kommentarer og 2 løsninger
Kopiere fra tabel til tabel
Hej, Jeg har to tabeller jeg gerne vil have lagt sammen til en. De har samme antal kolonner, med de samme navne(forskellige data). Hvordan får jeg lagt de to tabeller sammen til en ? Kopier og indsæt er ikke en mulighed ! /Ivan
To try the following examples in Microsoft Access, first create a new query in the Northwind sample database. Close the Show Table dialog box without specifying a table or query. Switch to SQL view, paste an individual example into the SQL window, and run the query. The following example retrieves the names and cities of all suppliers and customers in Brazil:
SELECT CompanyName, City FROM Suppliers WHERE Country = 'Brazil' UNION SELECT CompanyName, City FROM Customers WHERE Country = 'Brazil';
The next example retrieves the names and cities of all suppliers and customers located in Brazil:
SELECT CompanyName, City, 'Supplier' AS Source FROM Suppliers WHERE Country = 'Brazil' UNION SELECT CompanyName, City, 'Customer' FROM Customers WHERE Country = 'Brazil' ORDER BY City, Source;
The following example retrieves the names and IDs of all suppliers and customers. This union assumes that there are the same number of columns in each table.
another example SELECT "X1" As Navn, Null as Alder, Null as Køn, 1 as Sortering from X1 UNION SELECT Navn, Alder, Køn, 2 from X1 UNION SELECT "X2", Null, Null, 3 as Sortering from X2 UNION SELECT Navn, Alder, Køn, 4 from X2 UNION SELECT "X3", Null, Null, 5 as Sortering from X3 UNION SELECT Navn, Alder, Køn, 6 from X3 ORDER BY Sortering;
Nej, du kan sagtens bruge en forespørgsel af den type på en lokal database...
Det nemmeste du kan gøre er at tage min ovenstående kode, ændre tabelnavnene, så tabel1 er modtager-tabellen og tabel2 er kilde-tabellen. Opret så en makro, med 1 linie: KørSql - og indsæt SQL-sætningen.
Hej, Ja tak - i deler begge for ulejligheden. /Ivan
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.