Author > Creating questions and responses > Question type overview > Creating database questions > Creating database question loops
 
Creating database question loops
You may want to ask the same group of questions a number of times, for a different subject each time. One way to do this is to use a database question Loop. A database question loop is a container for a set of questions, whose category lists are generated by connecting to an external database, with options for determining how many times the questions are asked. The questions can be asked:
a fixed number of times
a number of times based on a list of entered responses
a variable number of times, where the number is taken from the response to a numeric question
once for each response in a single or multiple response question
a number of times based on a shared list of responses.
an unspecified number of times (known as an unbounded loop).
For example, suppose that you have a set of questions about vacations, such as, "How long the vacation lasted", "The number of people in your group", "Mode of travel", and you want to ask the questions for a number of vacations that the respondent has taken. You might choose to do this in a number of ways; here are some examples:
Decide on a fixed number in advance and ask all respondents to answer the questions this many times. For example, "For each of the last three vacations you took, please say...".
Begin by asking "How many vacations did you take last year?", then ask the questions once for each vacation that the respondent took.
Begin by asking the respondent to select a range of destinations and then ask the question once for each destination selected.
You can create a loop and then add questions to it, or you can select existing questions and group them in a loop. Loops can contain any type of question.
See Creating grid questions.
Notes
The Routings section of the Properties pane allows you to select an interviewing mode for the questionnaire. This controls the supported question types. Paper - Scanning mode does not support True or False, Date/Time, Loop, or Block question types. So if you select Paper - Scanning for the interviewing mode, selection of these question types will be automatically disabled.
When a loop is not directly in a routing (for example, in an existing block or loop), it is not considered a routing item. In these cases it is not possible to set a loop iterator from within UNICOM Intelligence Author. You can achieve similar functionality by creating a script routing item that sets the loop iterator (from within UNICOM Intelligence Professional for example).
Creating a new database question loop
1 From the menu, choose Insert > Question > Database Question > Loop or press Alt+I, Q, D, D, L
2 The Data Link Properties dialog displays, allowing you to provide the appropriate database provider and connection string information.
For more information on working with database questions that are derived from an Excel spreadsheet, see Working with database questions from Excel spreadsheets.
After specifying the appropriate data link property information the new multiple response database question displays in the Routings pane and in the Design pane.
The loop has an automatically generated name. Optionally, select the default name and change it to a more meaningful name. Loop names must be unique, cannot be empty and can contain only letters, numbers and the characters _ @ $ # . The first character must be a letter or _. Names cannot contain spaces.
Optionally, enter a loop description in the text field located beneath the Name field. The description will display at the top of the page.
3 Manually enter your connection string parameters in the Connection string field, or click Edit to launch the Data Link Properties dialog. The dialog provides options for selecting a database provider and defining the connection string parameters.
Note When the questionnaire file is opened from an UNICOM Intelligence Interviewer - Server Admin, UNICOM Intelligence Author does not provide the Data Link Properties dialog (the dialog can not be used against the connected UNICOM Intelligence Interviewer - Server Admin). When working with files opened against an UNICOM Intelligence Interviewer - Server Admin, you must manually enter the connection string in the Connection string field. After entering the appropriate string, click Test to verify whether the connection string will work against the UNICOM Intelligence Interviewer - Server Admin. Contact your UNICOM Intelligence Interviewer - Server Admin administrator if you need assistance in constructing a connection string.
4 Select the appropriate database table from the Table field menu. The list contains all tables in the selected database that correspond to the defined connection string.
5 Click Preview to open the Database Table Preview dialog. The dialog enables you to preview the table structure before actually mapping the database columns. For more information, see Database Table Preview dialog.
6 Use the Column mapping table to specify which database columns will provide the survey metadata. The list Available items to be mapped depends on whether the item being edited is a loop driver or a response list inside of a categorical question. Map the Available items to the Database columns by selecting the appropriate database columns from each item's column list.
String items can be mapped to any database table column.
Boolean items can only be mapped to database table columns that are also Boolean.
Numeric items can only be mapped to database table columns that are also Numeric.
Available items:
Item
Data Type
Database Categorical Questions
Loops
Name (required field)
String
Yes
Yes
Response (required field)
String
Yes
Yes
Key Code
String
Yes
No
File
String
Yes
Yes
Analysis value
String
Yes
No
Fixed
Boolean
Yes
Yes
Exclusive
Boolean
Yes
No
7 Click Filter to display the Filters dialog. The dialog allows you to write mrScript that can be used to further filter the response list returned from the database (via the Script tab), or compose SQL Where clauses in the provided WHERE section.
Viewing responses
After you have defined the connection string, selected a table, and mapped the columns, you can view the Responses table in the Responses tab. When working with database questions:
The data displayed in the table is read-only.
The Advanced Category Editor is not available.
You cannot assign custom properties to individual database items.
You cannot write translator notes for database items.
1 Click the Field Chooser button to select which fields will display in the Responses table.
Item
Database Categorical Questions
Loops
Name
Yes
N/A
Response
Yes
N/A
Key Code
Yes
N/A
File
Yes
N/A
Analysis value
Yes
N/A
Factor
Yes
N/A
Fixed
Yes
N/A
Exclusive
Yes
N/A
2 Click the Refresh button to view any changes that are made to the database items during the active UNICOM Intelligence Author session.
Iterator tab
For database question loops, the Iterator tab contains the same response table that displays for categorical database questions (via the Responses tab). Considering that the loop is driven by database data, the Iterator tab does not provide the same configuration options as a regular loop's Iterator tab. The iteration options are dictated by the database list.
Specifying additional question details in the Properties pane
See Specifying additional question details in the Properties pane.
Specifying response options
1 The Response Order field indicates the order in which responses are displayed to respondents. Choose Default to present responses in the order they appear in the response list, Random to present responses in a random order, Rotated to present responses in rotation so that each response takes a turn at being first in the list, or Reversed to present responses in reverse order so that the last response in the list appears first. Alternatively, select Ascending or Descending to present the responses in alphabetical order.
2 Click the SQL button to displays SQL tab in the Filters dialog, enabling you to compose SQL Where clauses in the provided WHERE section. For more information, see Filter dialog.
3 The Filter field enables you to filter the response list based on the responses to a previous categorical database question, or by non-database questions.
In the first box, choose one of All Responses, Chosen, Not Chosen, or Expert Expression. Selecting Expert Expression allows you to enter an expression filter in the At box.
Filtering database questions by another database question
1 In the At box, choose a database question whose answer controls the responses to be displayed for the current question. You are presented with the dialog that asks, Would you like to replace the current connection string for this question with the connection string of {selected question name}?.
If you select Yes, the current connection string is replaced with the selected database question's connection string.
If you select No, the current connection string is retained and the intersection of the two response lists is used as the basis for the filter options.
Filter selection
Connection string replaced
Connection string not replaced
All Responses
Intersection of Q1 and Q2
Q1
Chosen
Intersection of Q1(chosen) and Q2
Q1 chosen
Not Chosen
Intersection of Q1(not chosen) and Q2
Q1 not chosen
Expert Expression
User specified
User specified
When Expert Expression is selected, the At field changes to an ellipsis button that, when clicked, opens the Filter dialog. The dialog allows you to write mrScript that can be used to further filter the response list returned from the database (on the Script tab), or compose SQL Where clauses in the provided WHERE section. For more information, see Filter dialog.
When prompted, confirm that the responses defined for the chosen question (the parent question) may overwrite the response list for the current question.
Filtering database questions by non-database questions
In the At box, choose a non-database categorical question. The current connection string is not replaced, and a list of returned responses from the connection string is filtered based on the selected categorical question.
Filter selection
Q1 is NOT a database question
All Responses
Intersection of Q1 and Q2
Chosen
Intersection of Q1(chosen) and Q2
Not Chosen
Intersection of Q1(not chosen) and Q2
Expert Expression
User specified
See also
Creating database questions