Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql query help needed

Status
Not open for further replies.

shams123

Programmer
Jan 27, 2006
81
MY
Hi all,

I have a table that holds folder information (parent and children, identified by parentid). There's a different table for file information and a many-many relationship between them. This new table holds folder_id and file_id to keep track which files belong to which folders. E.g

Folder_ID Folder_Name ParentId
1 Top Folder 0
2 Sub Folder 1

File_Id FileName
1 File1

Id File_Id Folder_Id
1 1 2

Now the problem I am having is, that if a user selects any top folder (folder_Id:1 in this case), I have to list all the files that belong to that folder heirarchy (which includes children, subchildren etc). In the above case, selecting folder_id:1, would return back File_id:1. What kind of query I could use here?

The second issue is very much related to the above one, users can search for files based on name (and some other criteria) and I have to display the top folder that the files brought up by the search fall in. Like, if I search for '%File%' in the filename field, I should get back 'Top Folder' (since its the top most folder in the heirarchy under which the file falls). I am not sure how can I perform such search.

Would appreciate all help!

Cheers!
 
The version of SQL Server you use?

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
No recursive queries in SQL Server 2000 :-(


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top