If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Union Query with DAO 3.51

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-12-06, 02:20
waynewe waynewe is offline
Registered User
 
Join Date: Sep 2006
Posts: 4
Union Query with DAO 3.51

Hi

I'm trying to create a union query from 2 databases of similar structure. Both databases contain same tables and one is the production database the other an archive. And connecting to databases using DAO 3.51.

I have made an attempt however fails when run, if anyone can correct the syntax it would be appreciated.


sSql = "SELECT [dbFamilyName] & ', ' & [dbFirstName] AS dbPatient, [dbDob], [dbPatientId] " & _
"FROM C:\Shared\Data\meds.[Patient] " & _

"UNION SELECT [dbFamilyName] & ', ' & [dbFirstName] AS dbPatient, [dbDob], [dbPatientId] " & _
"FROM C:\Shared\meds-archive.[Patient] " & _

"ORDER BY [dbFamilyName], [dbFirstName];"


Now problem is gives a syntax error at FROM clause.
Reply With Quote
  #2 (permalink)  
Old 09-12-06, 03:44
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Hi

Welcome to the forum

Correct syntax for a heterogeneous query:
Code:
SELECT *
FROM Table1 IN 'C:\Remotedb.mdb'
Get it working for your first table and then create the union .

HTH
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #3 (permalink)  
Old 09-12-06, 18:22
waynewe waynewe is offline
Registered User
 
Join Date: Sep 2006
Posts: 4
Thank you, it works beaut! I can clearly see it was the syntax.
Reply With Quote
  #4 (permalink)  
Old 09-12-06, 23:17
waynewe waynewe is offline
Registered User
 
Join Date: Sep 2006
Posts: 4
Hi

Would it be possible to perforn an INNER JOIN using similar syntax?

SELECT Appointment.dbappointno, Appointment.dbdate, Appointment.dbtime, Appointment.dbstatus, Practitioner.dbpracno, Practitioner.dbsurname & ', ' & Practitioner.dbgivenname AS dbpractitioner
FROM Practitioner, Appointment
WHERE (dbpatno = 2769)
UNION SELECT Appointment.dbappointno, Appointment.dbdate, Appointment.dbtime, Appointment.dbstatus, Practitioner.dbpracno, Practitioner.dbsurname & ', ' & Practitioner.dbgivenname AS dbpractitioner
FROM Practitioner IN 'C:\Shared\med-archive.mdb', Appointment IN 'C:\Shared\med-archive.mdb'
WHERE (dbpatno = 2769)
ORDER BY dbdate DESC, dbtime DESC
Reply With Quote
  #5 (permalink)  
Old 09-13-06, 00:43
waynewe waynewe is offline
Registered User
 
Join Date: Sep 2006
Posts: 4
Thank you, I have found the solution.


SELECT Appointment.dbappointno, Appointment.dbdate, Appointment.dbtime, Appointment.dbstatus, Practitioner.dbpracno, Practitioner.dbsurname & ', ' & Practitioner.dbgivenname AS dbpractitioner
FROM Appointment INNER JOIN Practitioner ON Practitioner.dbpracno = Appointment.dbpracno IN 'C:\Shared\med.mdb'
WHERE (dbpatno = 2769)
UNION SELECT Appointment.dbappointno, Appointment.dbdate, Appointment.dbtime, Appointment.dbstatus, Practitioner.dbpracno, Practitioner.dbsurname & ', ' & Practitioner.dbgivenname AS dbpractitioner
FROM Appointment INNER JOIN Practitioner ON Practitioner.dbpracno = Appointment.dbpracno IN 'C:\Shared\med-archive.mdb'
WHERE (dbpatno = 2769)
ORDER BY dbdate DESC, dbtime DESC

It works like a treat.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On