ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 22nd, 2003, 12:40 PM
ashabi ashabi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 262 ashabi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 13 h 3 m 18 sec
Reputation Power: 8
Join tables in Access

how do i join tables in access and how do i get asp to output information from two separate tables that have the same primary key?

Reply With Quote
  #2  
Old September 22nd, 2003, 04:17 PM
imbrokn imbrokn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Location: NJ
Posts: 428 imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 34 m 8 sec
Reputation Power: 10
Send a message via AIM to imbrokn
select * from table1 inner join table2 on table1.primKey = table2.primKey

Reply With Quote
  #3  
Old September 22nd, 2003, 04:39 PM
ashabi ashabi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 262 ashabi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 13 h 3 m 18 sec
Reputation Power: 8
thanks. do i need to create another odbc connection for the second table before i write this statement?

Reply With Quote
  #4  
Old September 24th, 2003, 10:55 AM
davegerard davegerard is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 15 davegerard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 5 sec
Reputation Power: 0
Give this a shot...

<%
db = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=whatever.mdb"

set rs = server.createobject("adodb.recordset")
sql = "select Table1.Field1 as Field1, Table1.Field2 as Field2,"
sql = sql & " Table2.Field1 as Field3, Table2.Field2 as Field4"
sql = sql & " from Table1"
sql = sql & " INNER JOIN Table2 ON Table1.Id = Table2.Id"
rs.open sql, db, 3, 3
if not rs.eof then

response.write rs("Field1") & "<br>"
response.write rs("Field2") & "<br>"
response.write rs("Field3") & "<br>"
response.write rs("Field4") & "<br>"

end if
rs.close
set rs = nothing
%>

Reply With Quote
  #5  
Old September 29th, 2003, 07:49 AM
ashabi ashabi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 262 ashabi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 13 h 3 m 18 sec
Reputation Power: 8
ok. got the join table thing to work. but now from the page before it i have a search where it searches a date from table2. and then the results page needs to give me my results from both table1 and table2.
any ideas on the search script and the results script?

Reply With Quote
  #6  
Old September 29th, 2003, 01:22 PM
davegerard davegerard is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 15 davegerard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 5 sec
Reputation Power: 0
Assuming that Field2 from Table2 is the date field you would like to search and you are using Access, you can add this clause to your select statement. You must enclose the Date Value you are passing with # signs.

" where Table2.Field2 = #" & MyDate & "#"

If this doesn't seem to work try converting the value in your where clause to a date format, "cDate()", as follows:

" where Table2.Field2 = #" & cDate(MyDate) & "#"

Also, the part below that says MyDate = request("MyDate") is just the page requesting the date value from the previous page. You need to request it in order to include it into the where clause.


<%
db = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=whatever.mdb"

MyDate = request("MyDate")

set rs = server.createobject("adodb.recordset")
sql = "select Table1.Field1 as Field1, Table1.Field2 as Field2,"
sql = sql & " Table2.Field1 as Field3, Table2.Field2 as Field4"
sql = sql & " from Table1"
sql = sql & " INNER JOIN Table2 ON Table1.Id = Table2.Id"
sql = sql & " where Table2.Field2 = #" & MyDate & "#"
rs.open sql, db, 3, 3
if not rs.eof then

response.write rs("Field1") & "<br>"
response.write rs("Field2") & "<br>"
response.write rs("Field3") & "<br>"
response.write rs("Field4") & "<br>"

end if
rs.close
set rs = nothing
%>

Reply With Quote
  #7  
Old September 29th, 2003, 03:36 PM
ashabi ashabi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 262 ashabi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 13 h 3 m 18 sec
Reputation Power: 8
Something must be wrong with my search because if I leave out the MyDate stuff it displays the information properly. the moment i put a search function before it, it doesn't work. the database searches too long that i just get a server is too busy error. and there are only 4 entries in Table 2.

Reply With Quote
  #8  
Old September 29th, 2003, 08:11 PM
pda8333 pda8333 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 216 pda8333 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 6 m 31 sec
Reputation Power: 5
if u r calling from another page for MyDate, you need to either place a request.form or request.querystring depending on your previous page condition.

Code:
request.form("MyDate") or request.querystring("MyDate")

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Join tables in Access


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway