Simple access query

They have: 32 posts

Joined: Jan 2001

OK I feel like a moron!
My database experience is limited to SQL Server. I write Stored procs that contain multiple joins, and this stupid little access query is wearing me OUT! Here is what I am trying to do:

'html
inputbox - Book
inputbox - Chapter

SQL
sql = "select * from bibletable Where book = " & book & " and chapter = " & chapter

This is the error:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
/bible/default2.asp, line 32

OK I am ready for the simple solution.
Thanks

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

ahh yes, access.... (blah)
It's just plain weird. And seems to never work the first time.

are your values integers? or strings?
try putting quotes around your values ("WHERE book='" & book & "' ...")
try taking the spaces out from between the field=value

I have no idea what it is, just some quick thoughts....

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 359 posts

Joined: Mar 1999

if thats your exact sql statement, try counting your quote marks. think it's a little short on the number needed.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

nope... the number is fine.
You don't need a quote after chaper because its a variable, and not actually part of the SQL statement itself.

I don't see anything wrong with that SQL query. I'm sure that it works on other SQL servers. It's just that Access gets nit picky. Sad

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 359 posts

Joined: Mar 1999

sql = "select * from bibletable Where book = " & book & " and chapter = " & chapter
'

OK, let's break it down.
sql = "select * from bibletable Where book = " & book & " and chapter = "

I think it is running fine right up to that last quote and then it ends the sql statement and gives the error because it is looking for a value and it doesn't find it. Think if you moved the last " to after chapter, it would work.

I have one intranet website that is driven by access that has couple hundred statements just like this one and I can create and get the same error as 1aspfan is getting by removing the closing " mark.

Dan
Recycle Video Games Network

Stupidity killed the cat, curiosity was framed!

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

no....

chapter is an ASP variable. It cannot go inside the quotes, or the value will not be inserted into the query. If your hard set about putting a quote after chapter, you will need to do it like this:

sql = "select * from bibletable Where book = " & book & " and chapter = " & chapter & ""
'

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 359 posts

Joined: Mar 1999

Mark, I apologize. Your right about the quotes and if that were the problem, you get a termination error or something similar, not the one he is getting.

I just had this error come up a couple days ago, but for the life of me, can't remember what caused it. Have even been trying to recreate the error in the script i was working on at the time and still can't get it. If I didn't want it, probably would be there every time.

Hopefully 1aspfan has figured it out and will share it with us. Has my curiosity up now.

Dan
Recycle Video Games Network

Stupidity killed the cat, curiosity was framed!

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

No need to apologize. You just read it wrong Wink

I've use Access as a backend once that I can remember. I have a hard time trouble shooting it. So I try to stay away from it.

Mark Hensler
If there is no answer on Google, then there is no question.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Got in late on this one, try adding the single quotes as Mark said, and instead of using "SELECT *" do a "SELECT Book, field, field", there's an ADO bug that can fail on SELECT * (plus it's a good habit to get into anyways). I would write it as follows:

sql = "SELECT Book, field, field "
sql = sql & "FROM bibletable "
sql = sql & "WHERE book = '" & book & "' "
sql = sql & "AND chapter = '" & chapter & "'"
'

Just to verify line 32 is the sql right?

PJ | Are we there yet?
pjboettcher.com

They have: 32 posts

Joined: Jan 2001

Alright guys, after beating my head against a wall for a few hours this is what I came up with:

sql = "select * from bibletable where book like" &" '%%" & u_input & "%%' " & _
"and chapter like " &" '%%" & chapter & "%%' " & "and verse like " &" '%%" & verse & "%%' " & "and result like " &" '%%" & keywords & "%%' "

Picky Picky Picky

It seems as though we are all very fond af access.
I appreciate all of the help!

Have a great day!

Mike

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

What is the purpose to the double percent signs (%%)?
Shouldn't you only need one wild card?

They have: 32 posts

Joined: Jan 2001

Mark,

I do not really know! I just know that it works. If someone could explain it I would like to know. I may try to take one of them out see if it still works. I will try that tonight and let you know. I am really liking SQL Server at this time.

Later
Mike

They have: 46 posts

Joined: Dec 2000

I think it is working now simply because it has single quotes now.

I am sure after you state equals (WHERE this =) you need to put the critera in quotes.

I think just this would work:

sql = "select * from bibletable Where book ='" & book & "' and chapter ='" & chapter & "'"

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.