Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Shimmy, I have written a four-part article that addresses this issue - see <a href="http://www.4guysfromrolla.com/articles/082008-1.aspx" rel="nofollow noreferrer">Creating a Dynamic, Data-Drive User Interface</a>. The article looks at how to let a user define what data to store about clients, so it's not an exact examination of your question, but it's pretty close. Namely, my article shows how to let an end user define the type of data to store, which is along the lines of what you want.</p> <p>The following ER diagram gives the gist of the data model:</p> <p><img src="https://i.stack.imgur.com/o6Taq.gif" alt="Data model"></p> <p>Here, <code>DynamicAttributesForClients</code> is the table that indicates what user-created attributes a user wants to track for his clients. In short, each attribute has a <code>DataTypeId</code> value, which indicates whether it's a Boolean attribute, a Text attribute, a Numeric attribute, and so on. In your case, this table would store the questions of the survey.</p> <p>The <code>DynamicValuesForClients</code> table holds the values stored for a particular client for a particular attribute. In your case, this table would store the answers to the questions of the survey. The actual value is stored in the <code>DynamicValue</code> column, which is of type <code>sql_variant</code>, allowing any type of data - numeric, bit, string, etc. - to be stored there.</p> <p>My article does not address how to handle multiple-choice questions, where a user may select one option from a preset list of options, but enhancing the data model to allow this is pretty straightforward. You would create a new table named <code>DynamicListOptions</code> with the following columns:</p> <ul> <li><code>DynamicListOptionId</code> - a primary key</li> <li><code>DynamicAttributeId</code> - specifies what attribute these questions are associated with</li> <li><code>OptionText</code> - the option text</li> </ul> <p>So if you had an attribute that was a multiple-choice option you'd populate the drop-down list in the user interface with the options returned from the query:</p> <pre><code>SELECT OptionText FROM DynamicListOptions WHERE DynamicAttributeId = ... </code></pre> <p>Finally, you would store the selected <code>DynamicListOptionId</code> value in the <code>DynamicValuesForClients.DynamicValue</code> column to record the list option they selected (or use <code>NULL</code> if they did not choose an item).</p> <p>Give the article a read through. There is a complete, working demo you can download, which includes the complete database and its model. Also, the four articles that make up the series explore the data model in depth and show how to build a web-based (ASP.NET) user interface for letting users define dynamic attributes, how to display them for data entry, and so forth.</p> <p>Happy Programming!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload