473,408 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

SQL Query from two different access databases help required

Hi all,

Help will be much apreciated here.

How can I query two different access databases that has same table and fields.

This is how i access the one database but I want to be able to do it for both at the same time so that I have the rsult of available countries in both databases.

database1.mdb
database2.mdb

Set con = Server.CreateObject("ADODB.Connection")
con.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=c:\inetpub\wwwroot\database1.mdb"
sql_check = "select Country, count(*) as CountryCount from Property"
sql_check = sql_check & " GROUP BY Country"
Set rs = con.Execute(sql_check)

Now I can loop through the record set and show each Country name for this Database but I would like this loop to include both database answers

Any help will be much apreciated.

Hugo
Aug 22 '07 #1
5 4754
JamieHowarth0
533 Expert 512MB
Hi there,

There are a couple of ways you could do this:
  1. Create a second connection and recordset for your second Access DB, then merge the two recordsets together into a third recordset and use this third recordset as your resulting output;
  2. Create a single query in DB1 that imports the necessary data from DB2 and then joins the results of DB1 and DB2 together, then in ASP, retrieve the query from DB1 and output results.
I would say the second method is better in terms of performance, as it only involves one recordset being created on the server instead of 3.

If you want, PM/email me with links to your DBs and I can produce code for you.

medicineworker
Aug 23 '07 #2
Hi there,

There are a couple of ways you could do this:
  1. Create a second connection and recordset for your second Access DB, then merge the two recordsets together into a third recordset and use this third recordset as your resulting output;
  2. Create a single query in DB1 that imports the necessary data from DB2 and then joins the results of DB1 and DB2 together, then in ASP, retrieve the query from DB1 and output results.
I would say the second method is better in terms of performance, as it only involves one recordset being created on the server instead of 3.

If you want, PM/email me with links to your DBs and I can produce code for you.

medicineworker
Thanks for your reply !

I would like to try the first option first.

If I have made my conection one and use RS1 and second connection RS2 how do I merge the two ?

Never done this Merge so have no Idea.

Could you help me ?

Thanks

Hugo
Aug 23 '07 #3
why don't you want to use the second option? That option should work fine, even if you are not allowed to add queries to both MDB's, you can create a third MDB file, link both foreign tables, create an union query on that third mdb, and aim your recordset to the new third MDB.

to merge recordsets, I don't have an idea either, but I guess you should create a third table and populate it with both tables manually to achieve this.

Good Luck, Gustavo.
Aug 26 '07 #4
why don't you want to use the second option? That option should work fine, even if you are not allowed to add queries to both MDB's, you can create a third MDB file, link both foreign tables, create an union query on that third mdb, and aim your recordset to the new third MDB.

to merge recordsets, I don't have an idea either, but I guess you should create a third table and populate it with both tables manually to achieve this.

Good Luck, Gustavo.
THANKS DUDE !

I will give it a go !

Thanks

Hugo
Aug 27 '07 #5
JamieHowarth0
533 Expert 512MB
THANKS DUDE !

I will give it a go !

Thanks

Hugo
Quick follow-up - I provided Hugo with code on how to join the recordsets together by:
  1. retrieving then closing both recordsets (performance);
  2. using the GetRows method to convert both recordsets to arrays,;
  3. looping through both arrays and populating a third array;
  4. outputting results.
Which (in a general sense) looks a lot like this (presuming you have connected to your DB already and retrieved your two recordsets as ADODB.Recordset objects):

Expand|Select|Wrap|Line Numbers
  1. Dim arrRs1() As Array
  2. Dim arrRs2() As Array
  3. Dim arrJoinRecordsets() As  Array
  4. arrRs1 = myFirstRecordset.GetRows()
  5. arrRs2 =  mySecondRecordset.GetRows()
  6.  
  7. ‘Destroy recordsets – a performance  enhancement to free up additional  memory
  8. myFirstRecordset.Close
  9. mySecondRecordset.Close
  10.  
  11. ReDim  arrJoinRecordsets(UBound(arrRs1,1), (UBound(arrRs1,2) + UBound(arrRs2,2)))
  12. ‘  This particular line of code sets the upper boundary of your X-dimension (your  field columns), followed by the Y dimension (the sum of rows of your two  recordsets).
  13. ‘ The reason for doing this is so that we can iterate through  results of array 1, then array 2, and populate array 3, before destroying arrays  1 and 2.
  14.  
  15. ‘ Populate from array 1
  16. For X = 0 To UBound(arrRs1,  1)
  17.             For Y = 0 To UBound(arrRs1, 2)
  18.                          arrJoinRecordsets(X,Y) = arrRs1(X,Y)
  19.             Next
  20. Next
  21.  
  22. For X =  0 To UBound(arrRs2,1)
  23.             For Y = (UBound(arrRs1,2) + 1) To  UBound(arrRs2,2)
  24.                         arrJoinRecordsets(X,Y) =  arrRs2(X,(Y-UBound(arrRs2,2)))
  25.             Next
  26. Next
  27.  
  28. Set arrRs1 =  Nothing
  29. Set arrRs2 = Nothing
  30.  
  31. ‘Now print the entire array in tabular  form
  32. %>
  33. <table>
  34. <%
  35. For Y = 0 To  UBound(arrJoinRecordsets,2) %>
  36. <tr>
  37. <% For X = 0 To  UBound(arrJoinRecordsets,1)  %>
  38. <td><%=arrJoinRecordsets(X,Y)%></td>
  39. <% Next  %>
  40. </tr>
  41. <% Next %>
  42. </table>
  43.  
Hope other people find it useful. Any bugs/errors, let me know (I wrote it in about 5mins before I had to run out the front door a couple of mornings ago).

medicineworker
Aug 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
2
by: Mattyboy | last post by:
Guys I have built a database with saved queries that runs fine in Access but when I call it from the web using ASP, an exception occurs. I have tried multiple ways of testing the databases with...
96
by: Karen Hill | last post by:
SELECT surgeries.*, animals.* FROM surgeries INNER JOIN animals ON .=. AND WHERE ((.=Date()) Or .=Date()); I'm trying to write a query that joins two table together, animals and surgeries...
24
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every...
5
by: jonm4102 | last post by:
I'm trying to calculate the median of some numerical data. The data can only be found in a query (henceforth query 1) field I previously made, and I would prefer to calculate the median in a new...
9
by: noor.rahman | last post by:
I was wondering how it may be possible to query 2 MySQL databases using one query statement from PHP. For instance: SELECT database1.tableA.field1 UNION database2.tableB.field2. My concern...
2
by: Venk | last post by:
hi all, I saw one reply to arun on the subject "Dynamic Query in Ms-Access" by one Mr Rick I found it very useful. Now to extend this solution forward I have the following situation. I...
12
by: bhipwell via AccessMonster.com | last post by:
Hello, I have hit the "Cannot open any more databases" and "System resource exceeded" errors. Knew this was coming, but as I got closer to finishing the database, I hoped it wouldn't be an...
9
by: Sinner | last post by:
Hi, I have a field name 'USER' in tableMAIN. How do I replace the user names with corresponding user names. I can do that in xl using vlookup but now I'm trying to find a way to do that in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.