Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inner join works in Access database but not in ASp

Status
Not open for further replies.

Beng79

Technical User
Jan 5, 2006
48
HK
Good day to all,

I have write a inner query in Access database and it is able to produce results. I have 2 tables, Proj and Functional Features. The query is:

SELECT Proj.ProjID, Proj.ProjName, [Functional Feature].FeatID
FROM Proj INNER JOIN [Functional Feature] ON Proj.ProjID = [Functional Feature].ProjID;

When I copy over the query over to ASP, I got the following error when I try to run it ->
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

The code is below:
SQL = "SELECT ProjID, ProjName, [Functional Feature].FeatID, " _
& "FROM [Proj] INNER JOIN [Functional Feature] ON Proj.ProjID = Functional Feature.ProjID" _
& "WHERE ProjID LIKE '%" & Replace(strSearch, "'", "''") & "%';"_

 
try this:

Code:
SQL = "SELECT ProjID, ProjName, [Functional Feature].FeatID, " _ 
        & "FROM [Proj] INNER JOIN [Functional Feature] ON Proj.ProjID = [Functional Feature].ProjID" _
        & "WHERE ProjID LIKE '%" & Replace(strSearch, "'", "''") & "%';"_

you missed braces around Functional Feature...

-DNG
 
It also looks like there needs to be a space before the WHERE
 
I have tried amending the query by adding in the braces around Functional Feature and also tried adding the space before "Where"

I still get the same error. Anyone know of any link that has tutorials or tips on database queries in ASP script?

 
When debugging SQL statements in ASP, the first thing to try is to use Response.Write to output the SQL statement as it is immediately before execution.

There is often a formatting problem that will be quickly apparent and you will wonder why you didnt try that sooner.

If the SQL looks fine then copy it off your browser and open up MS Access --> New Query in Design Mode --> Add no tables --> Switch into SQL mode w/button in top left --> Paste the SQL copied out of the browser --> Run it and see what happens.
 
Development practices when using SQL/Interfaces faq333-4896 How can other tools help me develop ASP faq333-4770


 
Try this:

Code:
SQL = "SELECT ProjID, ProjName, [Functional Feature].FeatID, "_ 
        & "FROM [Proj] INNER JOIN [Functional Feature] ON Proj.ProjID = Functional Feature.ProjID "_
        & "WHERE ProjID LIKE '%" & Replace(strSearch,"'","") & "%'"

I don't know sir...I guess its broke.
 
Your also missing some table names in front of repetitive field names and I would double check your speling of the fieldnames and I would remove the semi colon:
Code:
SQL = "SELECT [highlight]Proj.[/highlight]ProjID, ProjName, [Functional Feature].FeatID, " _
        & "FROM [Proj] INNER JOIN [Functional Feature] ON Proj.ProjID = [Functional Feature].ProjID" _
        & " WHERE [highlight]Proj.[/highlight]ProjID LIKE '%" & Replace(strSearch, "'", "''") & "%'"_

Oh, and unless this SQL string is supposedto continue to the next line, that underscore at the end ofthe string shoudn't be there.

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top