473,654 Members | 3,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does Inner Join work in Access????

46 New Member
I have problem joining four tables using Inner Join in ACCESS DB,

I want to join 4 tables: 1, 2, 3 , 4 ....and query data in all these to see, i get a right url associated.

sql1-account id, account name
sql2-account id, email id
sql3-account id, contract number, maintenance start date, maintenance expiration date, download url, contact, maintenance status
sq4-account name, user id, pwd

first- i will check if the USER NAME and PWD I have is the saame as userid and the pwd in sql4
if so- match the account name with the userid and the pwd in sql4 to account id in sql1
then match the corresponding email id for that account id in sql2 with contact in sql3
and if email id=contact and maintenenace status is Y, then get -download url from sql3

for this i have written:
strSQL="SELECT sql4.[User Id], sql4.Pwd, sql1.[ACCOUNT NAME], sql2.[EMAIL ID], sql3.[download URL], "
strSQL= strSQL & " sql3.MAINTENACE _STATUS, sql3.[CONTRACT NUMBER] "
strSQL= strSQL & " FROM ((sql4 INNER JOIN sql1 ON sql4.[ACCOUNT NAME] = sql1.[ACCOUNT NAME]) "
strSQL= strSQL & " INNER JOIN sql2 ON sql1.[ACCOUNT ID] = sql2.[ACCOUNT ID]) "
strSQL= strSQL & " INNER JOIN sql3 ON sql2.[ACCOUNT ID] = sql3.ACCOUNTID "
strSQL= strSQL & " WHERE (((sql4.[User Id])='" & session(UserNam e) & "') AND ((sql4.Pwd)='" & Session(Passwor d) & "') "
strSQL= strSQL & " AND ((sql3.MAINTENA CE_STATUS)=Y))"

it gives me internal server error 5005

please help
tanya
Jun 4 '07 #1
3 2358
jhardman
3,406 Recognized Expert Specialist
Tanya,

I'm not sure about inner join, but the following should give the same effect and I use it all the time:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM sql1, sql2, sql3, sql4 WHERE "
  2. strSQL = strSQL & "sql4.[ACCOUNT NAME] = sql1.[ACCOUNT NAME] AND "
  3. strSQL= strSQL & "sql1.[ACCOUNT ID] = sql2.[ACCOUNT ID])"
  4. strSQL= strSQL & " AND sql2.[ACCOUNT ID] = sql3.ACCOUNTID "
  5. strSQL= strSQL & "AND (((sql4.[User Id])='" & session(UserName) & "') AND ((sql4.Pwd)='" & Session(Password) & "') "
  6. strSQL= strSQL & " AND ((sql3.MAINTENACE_STATUS)=Y))"
As far as I understand innerjoin, it sets up the same relationship as this. Try it out and tell me if it works.

Jared
Jun 5 '07 #2
chaitanya02
46 New Member
Tanya,

I'm not sure about inner join, but the following should give the same effect and I use it all the time:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM sql1, sql2, sql3, sql4 WHERE "
  2. strSQL = strSQL & "sql4.[ACCOUNT NAME] = sql1.[ACCOUNT NAME] AND "
  3. strSQL= strSQL & "sql1.[ACCOUNT ID] = sql2.[ACCOUNT ID])"
  4. strSQL= strSQL & " AND sql2.[ACCOUNT ID] = sql3.ACCOUNTID "
  5. strSQL= strSQL & "AND (((sql4.[User Id])='" & session(UserName) & "') AND ((sql4.Pwd)='" & Session(Password) & "') "
  6. strSQL= strSQL & " AND ((sql3.MAINTENACE_STATUS)=Y))"
As far as I understand innerjoin, it sets up the same relationship as this. Try it out and tell me if it works.

Jared
=============== =====

Jared, Thanks for replying my questions so patiently...

It didnt work...just gives an error Internal Server Error -500

I dont know for some reason, its not establishing connection to db, is what I feel...


I have a asp page- where customers enter thier user name and the pwd stored in sql server...Once they are logged in- they are taken to another page 2, where they would click on a link to download the software. I have redirected this link to another asap page-3, where I have connected to an access db and running above code....
So- I am not sure, where I am making mistake....Plea se help..I can send you the page where I am writing all this code. I am pretty sure, that there is no link between asp page-1 where the customer logs in and clicks on this link...
The asp page code where I have written the above code is:

------------------------------





<%@ language=VBScri pt%>

<% Option Explicit


'Declare Local Variables

Dim conn, strSQL
Dim strEmail,strUrl
Dim objMail, objRS
Dim strMessageBody, strDisclaimer
Dim sql1, sql2, sql3, sql4, UserName, Password
Dim CONTRACT NUMBER, MAINTENANCE_STA RT_DATE_C, MAINTENANCE_EXP IRATION_DATE_C, downloadURL
Dim ESD_Contact, MAINTENANCE_STA TUS, User_ID, Pwd
'End Variable Declaration

%>

<html><head><ti tle>Posting Mail</title></head>
<body bgcolor=acqua leftmargin='1' topmargin='1'>< table width='100%' height='100%' cellspacing='0' cellpadding='2' >
<tr align='left'><t d height='100%' width='145' valign='top'></td><td width='555' valign='top' align='left'>

'<%'get form elements and compose email

'Function ReplaceSpecial( str)
'If NOT IsNull(str) Then
'ReplaceSpecial = Replace(str, "'", "''")
'End If
'End Function

'strEmail = Trim(ReplaceSpe cial(Request.Fo rm("User_Email" )))

Set conn = Server.CreateOb ject("ADODB.Con nection")
conn.Provider=" Microsoft.Jet.O LEDB.4.0"

conn.Open "DSN=SQL"
Set objRS = Server.CreateOb ject("ADODB.Rec ordset")

session("UserNa me")="abd"
session("Passwo rd")="123"

strSQL = "SELECT * FROM sql1, sql2, sql3, sql4 WHERE "
strSQL = strSQL & "sql4.[ACCOUNT NAME] = sql1.[ACCOUNT NAME] AND "
strSQL= strSQL & "sql1.[ACCOUNT ID] = sql2.[ACCOUNT ID])"
strSQL= strSQL & " AND sql2.[ACCOUNT ID] = sql3.ACCOUNTID "
strSQL= strSQL & "AND (((sql4.[User Id])='" & session(UserNam e) & "') AND ((sql4.Pwd)='" & Session(Passwor d) & "') "
strSQL= strSQL & " AND ((sql3.MAINTENA CE_STATUS)=Y))"


'strSQL="SELECT sql4.[User Id] as UId, sql4.Pwd as pwd, sql1.[ACCOUNT NAME] as AccName, "
'strSQL= strSQL & " sql1.[ACCOUNT ID] as AccID , sql2.[EMAIL ID] as email, sql3.[download URL] as surl "
'strSQL= strSQL & " sql3.MAINTENACE _STATUS, sql3.[CONTRACT NUMBER] "
'strSQL= strSQL & " FROM ((sql4 INNER JOIN sql1 ON sql4.[ACCOUNT NAME] = sql1.[ACCOUNT NAME]) "
'strSQL= strSQL & " INNER JOIN sql2 ON sql1.[ACCOUNT ID] = sql2.[ACCOUNT ID] ) "
'strSQL= strSQL & " INNER JOIN sql3 ON sql2.[ACCOUNT ID] = sql3.ACCOUNTID "
'strSQL= strSQL & " WHERE sql4.[User Id]='abd' AND sql4.[Pwd]='123'"
'strSQL= strSQL & " WHERE sql4.[User Id]='" & session("UserNa me") & "'"
'strSQL= strSQL & " AND sql4.[Pwd]='" & session("Passwo rd") & "'"
'strSQL= strSQL & " AND sql3.MAINTENACE _STATUS=Yes"

'strSQL ="SELECT * FROM sql1, sql2, sql3, sql4 where sql3.User Id=Session (UserName) And Pwd=Session(Pas sword)"
'strSQL =strSQL & "And sql4.ACCOUNT NAME=sql1.ACCOU NT NAME And sql1.ACCOUNT ID=sql3.ACCOUNT ID"
'strSQL =strSQL & " And sql2.EMAIL ID=sql3.ESD Contact WHERE (sql3.MAINTENAN CE CONTRACT)='Y'"


objRS.open strSQL,conn

'response.write strEmail

'response.write strSQL


If NOT objRS.EOF Then
'CREATE THE MESSAGE OBJECT
response.write objRS("UId")
response.write objRS("Pwd")
response.write objRS("AccName" )
response.write objRS("AccID")
response.write objRS("email")
response.write objRS("surl")
strEmail=objRS( "email")
'objRS("sql3.ES D Contact")

strUrl="http://" & objRS("surl")
'objRS("sql3.do wnload URL")


Set objMail = Server.CreateOb ject("CDO.Messa ge")
'This section provides the configuration information for the remote SMTP server.

objMail.Configu ration.Fields.I tem ("http://schemas.microso ft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
objMail.Configu ration.Fields.I tem ("http://schemas.microso ft.com/cdo/configuration/smtpserver") ="mail.myserver .com"
objMail.Configu ration.Fields.I tem ("http://schemas.microso ft.com/cdo/configuration/smtpserverport" ) = 25
objMail.Configu ration.Fields.I tem ("http://schemas.microso ft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
objMail.Configu ration.Fields.I tem ("http://schemas.microso ft.com/cdo/configuration/smtpconnectiont imeout") = 60
'End remote SMTP server configuration section


objMail.Subject = "Download your software electronically"
objMail.From = "myID@myserver. com"
objMail.To = strEmail

'objMail.MailFo rmat = 0 'MIME Format
'objMail.BodyFo rmat = 0
strMessageBody = "Hi, You can download from this site <a href='" & strUrl & "' > " & strUrl & "</a>"


strMessageBody = strMessageBody & "<br><br>Th ank You,"
strDisclaimer = "<br><br><p><fo nt color='#777777' size='-1.5' face='Arial'><i >This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation.</i></font>"

'objMail.Body = strMessageBody & strDisclaimer
objMail.HTMLBod y= strMessageBody & strDisclaimer

response.write strMessageBody
'objMail.Send

objRS.Close

Set objRS = Nothing

%>

<table>
<tr><td class="normal"> Your request has been processed. Email address is: <%=strEmail%> Software URL is: <%=strUrl%>

</td></tr>
<tr><td class="normal"> </td></tr>
<tr><td class="normal"> Thank You</td></tr>
</table>
<%Else%>
<table>
<tr><td class="normal"> <font size='+1' color='Red'><b> Your request could not be processed. You will need to check the information that was submitted </b></font></td></tr>
</table>
<%End If%>

</td>
</tr>
</table>
<hr>

</body>
</html>




------------------------------------------
Jun 5 '07 #3
chaitanya02
46 New Member
=============== =====

Jared, Thanks for replying my questions so patiently...

It didnt work...just gives an error Internal Server Error -500

I dont know for some reason, its not establishing connection to db, is what I feel...


I have a asp page- where customers enter thier user name and the pwd stored in sql server...Once they are logged in- they are taken to another page 2, where they would click on a link to download the software. I have redirected this link to another asap page-3, where I have connected to an access db and running above code....
So- I am not sure, where I am making mistake....Plea se help..I can send you the page where I am writing all this code. I am pretty sure, that there is no link between asp page-1 where the customer logs in and clicks on this link...
The asp page code where I have written the above code is:

------------------------------





<%@ language=VBScri pt%>

<% Option Explicit


'Declare Local Variables

Dim conn, strSQL
Dim strEmail,strUrl
Dim objMail, objRS
Dim strMessageBody, strDisclaimer
Dim sql1, sql2, sql3, sql4, UserName, Password
Dim CONTRACT NUMBER, MAINTENANCE_STA RT_DATE_C, MAINTENANCE_EXP IRATION_DATE_C, downloadURL
Dim ESD_Contact, MAINTENANCE_STA TUS, User_ID, Pwd
'End Variable Declaration

%>

<html><head><ti tle>Posting Mail</title></head>
<body bgcolor=acqua leftmargin='1' topmargin='1'>< table width='100%' height='100%' cellspacing='0' cellpadding='2' >
<tr align='left'><t d height='100%' width='145' valign='top'></td><td width='555' valign='top' align='left'>

'<%'get form elements and compose email

'Function ReplaceSpecial( str)
'If NOT IsNull(str) Then
'ReplaceSpecial = Replace(str, "'", "''")
'End If
'End Function

'strEmail = Trim(ReplaceSpe cial(Request.Fo rm("User_Email" )))

Set conn = Server.CreateOb ject("ADODB.Con nection")
conn.Provider=" Microsoft.Jet.O LEDB.4.0"

conn.Open "DSN=SQL"
Set objRS = Server.CreateOb ject("ADODB.Rec ordset")

session("UserNa me")="abd"
session("Passwo rd")="123"

strSQL = "SELECT * FROM sql1, sql2, sql3, sql4 WHERE "
strSQL = strSQL & "sql4.[ACCOUNT NAME] = sql1.[ACCOUNT NAME] AND "
strSQL= strSQL & "sql1.[ACCOUNT ID] = sql2.[ACCOUNT ID])"
strSQL= strSQL & " AND sql2.[ACCOUNT ID] = sql3.ACCOUNTID "
strSQL= strSQL & "AND (((sql4.[User Id])='" & session(UserNam e) & "') AND ((sql4.Pwd)='" & Session(Passwor d) & "') "
strSQL= strSQL & " AND ((sql3.MAINTENA CE_STATUS)=Y))"


'strSQL="SELECT sql4.[User Id] as UId, sql4.Pwd as pwd, sql1.[ACCOUNT NAME] as AccName, "
'strSQL= strSQL & " sql1.[ACCOUNT ID] as AccID , sql2.[EMAIL ID] as email, sql3.[download URL] as surl "
'strSQL= strSQL & " sql3.MAINTENACE _STATUS, sql3.[CONTRACT NUMBER] "
'strSQL= strSQL & " FROM ((sql4 INNER JOIN sql1 ON sql4.[ACCOUNT NAME] = sql1.[ACCOUNT NAME]) "
'strSQL= strSQL & " INNER JOIN sql2 ON sql1.[ACCOUNT ID] = sql2.[ACCOUNT ID] ) "
'strSQL= strSQL & " INNER JOIN sql3 ON sql2.[ACCOUNT ID] = sql3.ACCOUNTID "
'strSQL= strSQL & " WHERE sql4.[User Id]='abd' AND sql4.[Pwd]='123'"
'strSQL= strSQL & " WHERE sql4.[User Id]='" & session("UserNa me") & "'"
'strSQL= strSQL & " AND sql4.[Pwd]='" & session("Passwo rd") & "'"
'strSQL= strSQL & " AND sql3.MAINTENACE _STATUS=Yes"

'strSQL ="SELECT * FROM sql1, sql2, sql3, sql4 where sql3.User Id=Session (UserName) And Pwd=Session(Pas sword)"
'strSQL =strSQL & "And sql4.ACCOUNT NAME=sql1.ACCOU NT NAME And sql1.ACCOUNT ID=sql3.ACCOUNT ID"
'strSQL =strSQL & " And sql2.EMAIL ID=sql3.ESD Contact WHERE (sql3.MAINTENAN CE CONTRACT)='Y'"


objRS.open strSQL,conn

'response.write strEmail

'response.write strSQL


If NOT objRS.EOF Then
'CREATE THE MESSAGE OBJECT
response.write objRS("UId")
response.write objRS("Pwd")
response.write objRS("AccName" )
response.write objRS("AccID")
response.write objRS("email")
response.write objRS("surl")
strEmail=objRS( "email")
'objRS("sql3.ES D Contact")

strUrl="http://" & objRS("surl")
'objRS("sql3.do wnload URL")


Set objMail = Server.CreateOb ject("CDO.Messa ge")
'This section provides the configuration information for the remote SMTP server.

objMail.Configu ration.Fields.I tem ("http://schemas.microso ft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
objMail.Configu ration.Fields.I tem ("http://schemas.microso ft.com/cdo/configuration/smtpserver") ="mail.myserver .com"
objMail.Configu ration.Fields.I tem ("http://schemas.microso ft.com/cdo/configuration/smtpserverport" ) = 25
objMail.Configu ration.Fields.I tem ("http://schemas.microso ft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
objMail.Configu ration.Fields.I tem ("http://schemas.microso ft.com/cdo/configuration/smtpconnectiont imeout") = 60
'End remote SMTP server configuration section


objMail.Subject = "Download your software electronically"
objMail.From = "myID@myserver. com"
objMail.To = strEmail

'objMail.MailFo rmat = 0 'MIME Format
'objMail.BodyFo rmat = 0
strMessageBody = "Hi, You can download from this site <a href='" & strUrl & "' > " & strUrl & "</a>"


strMessageBody = strMessageBody & "<br><br>Th ank You,"
strDisclaimer = "<br><br><p><fo nt color='#777777' size='-1.5' face='Arial'><i >This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation.</i></font>"

'objMail.Body = strMessageBody & strDisclaimer
objMail.HTMLBod y= strMessageBody & strDisclaimer

response.write strMessageBody
'objMail.Send

objRS.Close

Set objRS = Nothing

%>

<table>
<tr><td class="normal"> Your request has been processed. Email address is: <%=strEmail%> Software URL is: <%=strUrl%>

</td></tr>
<tr><td class="normal"> </td></tr>
<tr><td class="normal"> Thank You</td></tr>
</table>
<%Else%>
<table>
<tr><td class="normal"> <font size='+1' color='Red'><b> Your request could not be processed. You will need to check the information that was submitted </b></font></td></tr>
</table>
<%End If%>

</td>
</tr>
</table>
<hr>

</body>
</html>




------------------------------------------
Jared- It worked for me, the code that you have sent. ....Thanks a lot- there were few changes that had to be made though.....
Thanks so much
Tanya
Jun 5 '07 #4

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

Similar topics

1
1536
by: Steve | last post by:
Hi, I am real new to databases and hoping someone can help. Main-table is a huge spreadsheet that I imported into Access Site-table has a bunch of addresses pulled from Main-table, quite a few overlap in some areas and none of the fields are unique except the AddressKey which I created after pulling data from the Main-table. Why some fields are not unique I won't get into.
3
6634
by: media.opslag | last post by:
Hi, How can i get this to work in access / jet sql ??? Someone?? SELECT tbl1., tbl2. FROM tbl1 left outer join tbl2 on
52
6312
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
11
19960
by: YZXIA | last post by:
Is there any difference between explicit inner join and implicit inner join Example of an explicit inner join: SELECT * FROM employee INNER JOIN department ON employee.DepartmentID = department.DepartmentID
0
8372
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8706
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8591
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7304
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.