SQL Statement

They have: 10 posts

Joined: Aug 2003

Hi there!

I'm trying to get this SQL statement to work but I'm not sure the syntax. I'm calling on an Access database using ASP.

<?php

sql
= "SELECT Survey.Topic, Survey.ExpertId, Survey.[Last Name], Survey.[First Name] FROM Survey INNER JOIN [TopicTable] ON TopicTable.TopicID = [Survey].Topic WHERE (((TopicTable.TopicID)=" & Request.QueryString("TopicID") & ")) "

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn
?>

Ok...this code works but what I want to do is have like an OR that would do something like this (this code doesn't work )

<?php

sql
= "SELECT Survey.Topic, Survey.ExpertId, Survey.[Last Name], Survey.[First Name] FROM Survey INNER JOIN [TopicTable] ON TopicTable.TopicID = [Survey].Topic <strong>OR TopicTable.TopicID = [Survey].Topic2 OR TopicTable.TopicID = [Survey].Topic3 OR TopicTable.TopicID = [Survey].Topic4 OR TopicTable.TopicID = [Survey].Topic5</strong> WHERE (((TopicTable.TopicID)=" & Request.QueryString("TopicID") & ")) "

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn
?>

What I've bolded is what I want but I need the correct syntax. I want to be able to check and see if TopicTable.TopicID equals Survey.Topic, Survey.Topic2, Survey.Topic3, Survey.Topic4, or Survey.Topic5.

Can this even be done...I think it can...I don't use INNER JOIN often.

Hopefully this makes sense...

Thanks!

druagord's picture

He has: 335 posts

Joined: May 2003

i would try to put it in the where clause

sql = "SELECT Survey.Topic, Survey.ExpertId, Survey.[Last Name], Survey.[First Name] FROM Survey WHERE (TopicTable.TopicID = [Survey].Topic OR TopicTable.TopicID = [Survey].Topic2 OR TopicTable.TopicID = [Survey].Topic3 OR TopicTable.TopicID = [Survey].Topic4 OR TopicTable.TopicID = [Survey].Topic5) AND (((TopicTable.TopicID)=" & Request.QueryString("TopicID") & ")) "

IF , ELSE , WHILE isn't that what life is all about

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

The extended OR join should be fine... maybe inclose it in parenthesis?

table_name ON (long OR stuff)

They have: 10 posts

Joined: Aug 2003

I get the following error for both:

Error Type:
Microsoft JET Database Engine (0x80040E10)
No value given for one or more required parameters.
/News_Events/NSCC_Experts/qry_by_topic.asp, line 38

What I'm trying to set up is on one page a listing of "topics"; when you click on the topic it will give you a list of people who belong to that topic. I want to allow any given person to belong to a max of 5 topics and them to be listed accordingly.

Right now the topics listing works. If I only allow for one topic per person the whole thing works but I need to allow for them to possibly be under 5 categories.

It's probably something really simple I'm not doing right. I wonder if it's something in my database...

druagord's picture

He has: 335 posts

Joined: May 2003

Usually i design those relations with an intermediate table wich link users to topics. anyway for the error you get now could you ask for a print the sql statement to make sure you have the topicid inserted in it.

IF , ELSE , WHILE isn't that what life is all about

They have: 10 posts

Joined: Aug 2003

My database has a topics table and a table called survey. In survey i have fields called Topic, Topic2, Topic3, Topic4 and Topic5. These fields are linked to the TopicID and the topic name. Displayed in the Survey table is the topic name so those who report will see the name of the topic and not just a number.

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.