...

View Full Version : sql query problems



Svenson
08-26-2004, 09:56 PM
Hello,

Once again I am having problems that I think are probably simple formatting mistakes or something, but I need to get this job done before i can take the time to really learn the language, so I'm hoping someone can help me out.

OK, I think this is all of the relevant code:
The stuff for opening the connection I think works fine, so I won't paste all of that.


Dim Query_Sport
Dim Query_Sex

Query_Sport = Int(Request.QueryString("sport"))
Query_Sex = Int(Request.QueryString("sex"))

sql = "SELECT * FROM [Students] WHERE Sport1 = " & Query_Sport

sql = sql & " AND Sex = " & Query_Sex


Now, if I do a response.write, I can see the the querystring is 2, and there are definitely students whose sex = 2, but I get no return.
And if I query for males (sex=1), I get back only males.
Confusing :)

Let me know if you need to see more code.

Thanks a lot,
Brian Hill

Morgoth
08-26-2004, 10:33 PM
Are you executing your sql statement?

Example:
Set oRS = oConn.Execute(SQL)

Svenson
08-26-2004, 10:35 PM
Yup:

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn, 3, 3
If rs.eof Then
rs.AddNew
End If
Set Session("Students_rs") = rs

And it works if you query different sports, so I'm guessing the database stuff is working ok.

-Brian

raf
08-26-2004, 10:46 PM
What exactly is the problem? If 'the database stuff' is working, why do you then only post the querycomposition?

You did try a

response.write SQL

right? So then just copy paste the generated sql in a querywindow of your db and look if it returns records.

Svenson
08-26-2004, 10:50 PM
OK, I don't feel too smart now. :)

I was searching for female baseball players, and it seems I hadn't put one in the database.

Sorry.
-Brian

raf
08-26-2004, 11:03 PM
OK, I don't feel too smart now. :)

I was searching for female baseball players, and it seems I hadn't put one in the database.

Sorry.
-Brian
Believe me, we've all been there.
... female baseball players ... that's enough to make you loose focus :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum