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 |
morleyz
Starting Member
17 Posts |
Posted - 2010-11-24 : 10:10:23
|
We have a survey system that allows users to build surveys and send them out to groups of users by e-mail. The process of setting up a survey is to create questions, then organize the questions into a template (order and layout of the questions) that gets assigned to a survey group (start date, end date, recipients, etc.) As the system has grown, I need a way to determine questions that aren't used in any survey group.Relevant data structure:questions_table: fields: id, questiontemplates_table: fields: id, template_nametemplate_match_table: fields: template_id (from templates_table), question_id (from questions_table), template_ordersurvey_group_table: id, group_name, template_id (from templates_table), start_date, end_dateThe question I need to answer is: What questions are not used by any survey groups?I am able to query for questions that aren't in any templates. I can also query for templates that aren't in use by any survey groups, but what happens over time is that as the groups are purged, the questions and templates hang around and the way our system works I really need a way to find the questions that aren't in any groups and I just am not sure where to start.Any help would be greatly appreciated.Thanks. |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-11-24 : 10:30:27
|
select q.*from questions qleft join templates_match tmon tm.question_id = q.question_idleft join survey_group sgon sg.template_id = tm.template_idwhere sg.template_id is null==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
morleyz
Starting Member
17 Posts |
Posted - 2010-11-24 : 14:51:01
|
I think this is very close, but it is returning some values it shouldn't. It looks like if a question belongs to a template that doesn't have survey group assigned, that question is returned even if that question is in a different template and group combination.It is possible for questions to be used in multiple templates and multiple templates to be used in multiple survey groups.I tried tweaking it different ways and still got the same results. |
 |
|
|
|
|
|
|