   [web] Another Noob MS SQL Query Question
  Hi, I'm still bad at SQL, and am trying to speed/secure up some of our searches by putting them in a stored procedure...here's basically what the tables look likeLinks TableID Page_ID  Value_1   Value_2Pages TableID Folder_IDValue_1   Value_2Folders TableIDTitle    Parent_Folder_IDOur basic structure if you can't tell by looking, is that Folders contain other folders and pages, and pages contain links.And what I basically want to do, is search all the links within a folder..(meaning all the links on the pages that are in the specific folder)what just have some cheesy script up right now using inline SQL that just runs like a bunch of different queries to get the results...but i'd like to make this into a single stored procedure if this is possible..here is kinda what i'm workin with now (I'm terrible with stored procedures and sql so bare with me)CREATE PROCEDURE usp_search   @folderToSearch int,@searchString varchar(512)ASBEGINSET NOCOUNT ON;SELECT * FROM Links WHERE Value_1 LIKE '%' + @searchString + '%' WHERE    //confused on this part...WHERE the page_id is within the folder of the @folderToSearch folderENDGOIf it doesn't make sense what i'm trying to do...here is an example of the bad c# code i'm using write now to accomplish the same thingvoid mainmethod(){    string sSQL = "SELECT ID FROM Pages WHERE Folder_ID = " + folderToSearch;    int[] pagesToSearch = RunQueryAndReturnIntArray(sSQL);   string sSQL = BuildQuery(pagesToSearch, searchQuery);   RunMySearch(sSQL);}public string BuildQuery(int[] ids, string searchQuery){   string sSQL = "SELECT * FROM Links WHERE Value_1 LIKE '%" + searchQuery    + "%' AND";   sSQL += "(";   foreach (int id in ids)  sSQL += " Page_ID = " + id + " OR"; sSQL = sSQL.Remove(sSQL.Length - 3);   sSQL += ")";   return sSQL;}Any insight would be great...I have no idea how this type of searching is normally done (if it is)...so I did it the only way I could think of...but this is obviously not safe at all, and probably not very efficient either, so even just little pointers would be helpful.Thanks for reading.ArchG   
  You should be joining the tables together.I assume something like this will work for you:create proc usp_search   @folderToSearch int,@searchString varchar(512)asset nocount onselect l.ID LinkId, l.Value_1 LinkValue1, l.Value_2 LinkValue2,p.Value_1 PageValue1, p.Value_2 PageValue2,f.Title FOlderTitlefrom Links ljoin Pages pon l.Page_ID = p.IDjoin Folders fon f.ID = p.FOlder_IDwhere f.Title = @folderToSearchand l.Value_1 like '%' + @searchString + '%'