Tag filtering Query using T-SQL and Linq-to-SQL?
- by EdenMachine
I'm trying to figure out how to allow a user to enter in a string of tags (keywords separated by spaces) in a textbox to filter a grid of results.
Here are the tables:
PACKETS
*PacketID
Name
PACKETTAGS
*PacketTagID
PacketID
TagID
Tags
*TagID
Name  
Here is the basic query without the WHERE parameters:
SELECT     
       Packets.Name, Tags.Name AS Tag, PacketTags.PacketTagID
FROM         
       Packets 
INNER JOIN
       PacketTags ON Packets.PacketID = PacketTags.PacketID 
INNER JOIN
       Tags ON PacketTags.TagID = Tags.TagID
I need to filter out all the Packets that don't have tags that match any of the words BUT ALSO ONLY include the Packets that have the tags entered in the string of text (spaces separate the tags when entered into the textbox)
I'm starting with the basics by figuring this out in t-SQL first but ultimately I need to be able to do this in Linq-to-SQL