Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
I have a table structure like so:

Article
-------
ArticleID
Text

Tag
-------
TagID
Text

ArticleTag
-------
ArticleID
TagID

I need to write a stored procedure that will select all articles tagged with at least so many tags (i.e., "code", "project", "sql", I want all articles that have at least those tags in them). Thanks!
Posted
Comments
ArunRajendra 1-Aug-13 23:21pm    
So you want to show the article which linked with "code", "project" or "sql"?
Jack R. Schaible 1-Aug-13 23:37pm    
Yeah, any articles which contain those tags, at least (they can have more, as long as they have at least those ones).

1 solution

It's a bit tricky on the stored procedure part since you can have indefinite number of tags as input. My suggestion is to use dynamic SQL[^] in creating the query. Basically, you put all your tags on the input parameter on your stored procedure, do the necessary parsing and string manipulation on the parameter, and then integrate in on the WHERE clause of your query. The link has examples provided. You might want to check it out.
 
Share this answer
 
Comments
Jack R. Schaible 2-Aug-13 1:12am    
*sigh* That's what I was afraid of. But thanks for the link, I'll check it out as soon as I get a chance!
walterhevedeich 2-Aug-13 1:39am    
You mean dynamic SQL?
Jack R. Schaible 2-Aug-13 1:57am    
I never got into it. It seems rather intimidating, lol.
walterhevedeich 2-Aug-13 2:01am    
It shouldn't take you long to be familiar with it, considering you have spent a couple of years programming. ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900