Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
cok
Starting Member
1 Post |
Posted - 2007-10-24 : 14:31:28
|
| Hi,I have a problem. I have questions, to a question there can be arbitrary groups and to every group there can be arbitrary conditions. To have permission to “see” an question you have to have at least one condition from every group which is in the question.I have three tables: Question, QuestionGroup and GroupCondition.QuestionQuestionId | Bla | Bla15 | as | asd16 | ef | asdasQuestionGroupfkey_GroupID | fkey_QuestionID1 | 152 | 153 | 16GroupConditionPkey_GroupId | fkey_ConditionId1 | 1011 | 1022 | 1033 | 1013 | 1023 | 103 So I need a select which returns all QuestionId from Question depending on the conditions I have. So to get QuestionId (15) I need following: (101 or 102) and (103), to get acess to QuestionId 16 I need (101 or 102 or 103). I hope I have been clear enough.. :)Best regardscarl |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-10-24 : 16:34:35
|
| [code]DECLARE @Question TABLE (QuestionID INT)INSERT @Question SELECT 15UNION ALL SELECT 16DECLARE @QuestionGroup TABLE(GroupID INT, QuestionID INT)INSERT @QuestionGroup SELECT 1, 15UNION ALL SELECT 2, 15UNION ALL SELECT 3, 16DECLARE @GroupCondition TABLE (GroupId INT, ConditionId INT)INSERT @GroupCondition SELECT 1, 101UNION ALL SELECT 1, 102UNION ALL SELECT 2, 103UNION ALL SELECT 3, 101UNION ALL SELECT 3, 102UNION ALL SELECT 3, 103 SELECT Condition.ConditionIDFROM @GroupCondition AS ConditionINNER JOIN @QuestionGroup AS QuestionGroup ON Condition.GroupID = QuestionGroup.GroupIDWHERE QuestionGroup.QuestionID = 15[/code] |
 |
|
|
|
|
|
|
|