D
Dave
I have a database that has articles that are classified by topic. The
article and topic are a many to many relationship that is implemented
through the junction table articletopic.
I wrote a query that will return all of the articles that are related to 2
specified topics (e.g., give me all of the articles that are related to
topicid 107 AND topicid 87).
This was a more difficult query to write than I first realized but the
following syntax gives me what I need...
SELECT Article.date2
,Topic.topic
,Topic.topicid
,Article.articleid
,Article.title
,Article.abstract
,(SELECT note FROM articletopic WHERE articleid=x.articleid AND
topicid=x.topicid) AS note_x
,(SELECT note FROM articletopic WHERE articleid=y.articleid AND
topicid=y.topicid) AS note_y
FROM (([SELECT atp.articleid, atp.topicid FROM articletopic atp WHERE
atp.topicid = 87]. AS x
INNER JOIN [SELECT atp2.articleid, atp2.topicid FROM articletopic atp2
WHERE atp2.topicid = 107]. AS y ON x.articleid = y.articleid)
INNER JOIN Article ON x.articleid = Article.ArticleID)
INNER JOIN Topic ON x.topicid = Topic.TopicID
ORDER BY date2 DESC;
My problem is that I cannot paramatize thuis query.
Notice that the topic ids are hard-coded in the two derived tables I use to
get my two topic sets. But I need them to be parameters so they can be
changed on the fly.
If I try to write the derived tables like this...
SELECT atp.articleid, atp.topicid FROM articletopic atp WHERE atp.topicid
= [p1]
... I get a syntax a error in JOIN operation.
This is noit a problem with a SQL Server stored procedure but can anyone
give me an idead on how to do it in Access 2003?
Thanks
Dave
article and topic are a many to many relationship that is implemented
through the junction table articletopic.
I wrote a query that will return all of the articles that are related to 2
specified topics (e.g., give me all of the articles that are related to
topicid 107 AND topicid 87).
This was a more difficult query to write than I first realized but the
following syntax gives me what I need...
SELECT Article.date2
,Topic.topic
,Topic.topicid
,Article.articleid
,Article.title
,Article.abstract
,(SELECT note FROM articletopic WHERE articleid=x.articleid AND
topicid=x.topicid) AS note_x
,(SELECT note FROM articletopic WHERE articleid=y.articleid AND
topicid=y.topicid) AS note_y
FROM (([SELECT atp.articleid, atp.topicid FROM articletopic atp WHERE
atp.topicid = 87]. AS x
INNER JOIN [SELECT atp2.articleid, atp2.topicid FROM articletopic atp2
WHERE atp2.topicid = 107]. AS y ON x.articleid = y.articleid)
INNER JOIN Article ON x.articleid = Article.ArticleID)
INNER JOIN Topic ON x.topicid = Topic.TopicID
ORDER BY date2 DESC;
My problem is that I cannot paramatize thuis query.
Notice that the topic ids are hard-coded in the two derived tables I use to
get my two topic sets. But I need them to be parameters so they can be
changed on the fly.
If I try to write the derived tables like this...
SELECT atp.articleid, atp.topicid FROM articletopic atp WHERE atp.topicid
= [p1]
... I get a syntax a error in JOIN operation.
This is noit a problem with a SQL Server stored procedure but can anyone
give me an idead on how to do it in Access 2003?
Thanks
Dave