| Author |
Topic |
|
ann
Posting Yak Master
220 Posts |
Posted - 2009-09-21 : 16:33:55
|
| I have a db that contains file information for files that sit on the server. In the db there are tables that include: FileInfo, Distribution, Users DistributionList ans AsocDistThe Distribtion table contains a name for a distribtion, the distribtionList the users associated witht the distribtion, and the AssocDist table contains the FileInfo and Dist associationTable: FileInfoFields: FileID, FileName, LocationData: 1, SomeTxt.txt, ServerA 2, Spreadsheet.xls, ServerBTable: DistribtionFields: DistID, DistNameData: 1, Month-End Recievables 2, Year-End ProfitsTable: DistribtionListFields: DistID, UserIDData: 1, 12 1, 15Table: AssocDistFields: FileID, DistIDData: 1, 1 2, 2Table: UsersFields: UserID, Fname, LNameData: 12, Mickey, Mouse 15, Daffy, DuckQuery: Get FileInfo data where userID = 12Results Wanted: 1, SomeTxt.txt, ServerAI need to get the FileName, Location for a specific user and I can't figure out how to get itAny help would be appreciated.Thanks |
|
|
ann
Posting Yak Master
220 Posts |
Posted - 2009-09-21 : 16:46:42
|
| So I came up with:Select * From UploadedFileswhere UploadFileID in(select UploadFileID from AssocDist Where DistID in (select DistID from DistList Where userID = 12))Does that seem right? It gives me the results I want, but I'm working with such a small subset of data for testing - or is there a better way to do thi? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-09-21 : 21:31:23
|
[code]DECLARE @FileInfo TABLE( FileID int, [Filename] varchar(20), Location varchar(10))INSERT INTO @FileInfoSELECT 1, 'SomeTxt.txt', 'ServerA' UNION ALLSELECT 2, 'Spreadsheet.xls', 'ServerB'DECLARE @Distribution TABLE( DistID int, DistName varchar(30))INSERT INTO @DistributionSELECT 1, 'MONTH-END Recievables' UNION ALLSELECT 2, 'YEAR-END Profits'DECLARE @DistributionList TABLE( DistID int, UserID int)INSERT INTO @DistributionListSELECT 1, 12 UNION ALLSELECT 1, 15DECLARE @AssocDist TABLE( FileID int, DistID int)INSERT INTO @AssocDistSELECT 1, 1 UNION ALLSELECT 2, 2DECLARE @Users TABLE( UserID int, Fname varchar(10), LName varchar(10))INSERT INTO @UsersSELECT 12, 'Mickey', 'Mouse' UNION ALLSELECT 15, 'Daffy', 'Duck'SELECT fi.FileID, fi.[Filename], fi.LocationFROM @DistributionList dl INNER JOIN @AssocDist ad ON dl.DistID = ad.DistID INNER JOIN @FileInfo fi ON ad.FileID = fi.FileIDWHERE dl.UserID = 12/*FileID Filename Location ----------- -------------------- ---------- 1 SomeTxt.txt ServerA(1 row(s) affected)*/[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|