|
-
Jul 30th, 2011, 04:06 PM
#1
Thread Starter
Frenzied Member
inner join syntax error
hey all.
i've gone over various threads with the error and most end up being placement of brackets, etc.
I can't seem to figure this out, and i'm sure its really simple.
First off, this is going to an Access Database that has linked tables tied to an ORACLE DB.
So here is my SQL string that is throwing the error.
Code:
strSQL = "SELECT SYSTEM.EMAIL" & _
"FROM CUSTOMER INNER JOIN SYSTEM" & _
"ON CUSTOMER.ID = SYSTEM.ID" & _
"WHERE (((CUSTOMER.STATE) = '" & mySt & "')) "
It;s basically pulling an email address based on the state in the customer table matching mySt variable. using ID's as the comparison keys, or primary key if you will.
I tried the following also, with no success.
Code:
FROM CUSTOMER INNER JOIN (SYSTEM ON CUSTOMER.ID = SYSTEM.ID)
not really sure why the error...since i pulled the syntax directly from SQL view in the access database, after creating a query in design view. only difference is that i added in a variable mySt , instead of picking one myself. i've also viewed the mySt variable just before the sqlStr gets ran into a record set, and its contents matches fine.
any ideas?
:::`DISCLAIMER`:::
Do NOT take anything i have posted to be truthful in any way, shape or form.
Thank You!
--------------------------------
"Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
"Finaly I can look as gay as I want..." - NoteMe
Languages: VB6, BASIC, Java, C#. C++
-
Jul 30th, 2011, 07:51 PM
#2
Re: inner join syntax error
IMO 'SYSTEM' is a problem name or a reserved word, try using brackets around it []
Also, visit --> http://allenbrowne.com/AppIssueBadWord.html#S
JG
-
Jul 31st, 2011, 10:39 AM
#3
Thread Starter
Frenzied Member
Re: inner join syntax error
Still having the same problem, even if changing the table name for system. e.g. (SYSTEM_ROLE)
It's odd, since the exact syntax is working fine inside Access itself. Yet from my VB6 program, it is throwing the inner join syntax error.
:::`DISCLAIMER`:::
Do NOT take anything i have posted to be truthful in any way, shape or form.
Thank You!
--------------------------------
"Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
"Finaly I can look as gay as I want..." - NoteMe
Languages: VB6, BASIC, Java, C#. C++
-
Aug 1st, 2011, 08:48 AM
#4
Lively Member
Re: inner join syntax error
Put a space before each double-quote. I don't know if you put it on multiple lines for demonstration purposes on this board or it's all on one line in code but the way you have it written, would translate into
SELECT SYSTEM.EMAILFROM CUSTOMER INNER JOIN SYSTEMON CUSTOMER.ID = SYSTEM.IDWHERE (((CUSTOMER.STATE) = '" & mySt & "')) " the ones in bold are missing spaces.
Try
Code:
strSQL = "SELECT SYSTEM.EMAIL " & _
"FROM CUSTOMER INNER JOIN SYSTEM " & _
"ON CUSTOMER.ID = SYSTEM.ID " & _
"WHERE (((CUSTOMER.STATE) = '" & mySt & "')) "
-
Aug 1st, 2011, 09:37 AM
#5
Re: inner join syntax error
I would take it one step further, and "stretch" out the string to multiple lines
Code:
strSQL = "SELECT SYSTEM.EMAIL "
strSQL = strSQL & "FROM CUSTOMER "
strSQL = strSQL & "INNER JOIN SYSTEM ON CUSTOMER.ID = SYSTEM.ID "
strSQL = strSQL & "WHERE (((CUSTOMER.STATE) = '" & mySt & "')) "
Now it is a bit easier to read. Those spaces mentioned are EXTREMELY important.
Now I'll take it two steps further and say you really shouldn't be using Inline SQL anyway. Look into parametized queries.
-
Aug 1st, 2011, 12:57 PM
#6
Thread Starter
Frenzied Member
Re: inner join syntax error
 Originally Posted by Hack
I would take it one step further, and "stretch" out the string to multiple lines
Code:
strSQL = "SELECT SYSTEM.EMAIL "
strSQL = strSQL & "FROM CUSTOMER "
strSQL = strSQL & "INNER JOIN SYSTEM ON CUSTOMER.ID = SYSTEM.ID "
strSQL = strSQL & "WHERE (((CUSTOMER.STATE) = '" & mySt & "')) "
Now it is a bit easier to read. Those spaces mentioned are EXTREMELY important.
Now I'll take it two steps further and say you really shouldn't be using Inline SQL anyway. Look into parametized queries.
This was the problem.
mySt variable needs to contain double quotes around it inside the sql string. Code above ends up sending the following in the string:
Code:
WHERE (((CUSTOMER.STATE) = 'GA' ))
I'm now reading up on the parametized queries from threads on the forums here.
Still curious though, how would I include the double quotes in that statement using my current format. '"" mySt ""' and " ' " turns it into a comment.
I definitely see what using parameter based queries would be helpful though!
:::`DISCLAIMER`:::
Do NOT take anything i have posted to be truthful in any way, shape or form.
Thank You!
--------------------------------
"Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
"Finaly I can look as gay as I want..." - NoteMe
Languages: VB6, BASIC, Java, C#. C++
-
Aug 1st, 2011, 01:33 PM
#7
Re: inner join syntax error
You wouldn't use quotes.
You would use the @ sign and variable or control name
-
Aug 1st, 2011, 01:51 PM
#8
Thread Starter
Frenzied Member
Re: inner join syntax error
 Originally Posted by Hack
You wouldn't use quotes.
You would use the @ sign and variable or control name
Thanks.
Are there any other good resources to read here on the parameter queries.
I've found a few with great examples.
http://www.vbforums.com/showthread.php?t=548787
http://www.vbforums.com/showthread.php?t=381391
Always picky on outside sources found via google.
:::`DISCLAIMER`:::
Do NOT take anything i have posted to be truthful in any way, shape or form.
Thank You!
--------------------------------
"Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
"Finaly I can look as gay as I want..." - NoteMe
Languages: VB6, BASIC, Java, C#. C++
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|