Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get data from a property-value table structure?
    primarykey
    data
    text
    <p>I got 3 tables as follow:</p> <pre><code>Table 1: FormFields (FieldID, FormID, Title, DateModified, ...) Table 2: ReportItems (ReportItemID, ReportID, FormID, Title, DateModified, ...) Table 3: FormValues (ValueID, FormID, FieldID, Value, UserName, DateModified, ...) </code></pre> <p>For example I have selected 2 Fields of FormFields as my ReportItems. These 2 fields are a question and answer couple. Each question can have 1 answer or it could be NULL. The key is the result should be such a html data list (dl) with 'dt's and 'dd's like this:</p> <pre><code>ReportID FormID FieldID Value (Question1) UserName ReportID FormID FieldID Value (Answer1) UserName ReportID FormID FieldID Value (Question2) UserName ReportID FormID FieldID Value (Answer2) UserName ReportID FormID FieldID Value (Question3) UserName ReportID FormID FieldID Value (Answer3) UserName Question 1 Answer 1 Question 2 Question 3 Answer 3 Question 4 Question 5 Answer 5 </code></pre> <p>I used a query like this, but it doesn't return the result I wish:</p> <pre><code>select rf.FormID, rf.FieldID, rf.ReportItemTitle, v.Value from (select r.ReportItemID, r.FormID, r.FieldID, r.Title as ReportItemTitle from (select ReportItemID, ReportID, FormID, FieldID, Title from ReportItems where FormID = '2D6C42E1-0C95-4E40-B792-A17E00C001BF' and ShowInList = 0) r JOIN (select FormID, FieldID, Title from FormFields where FormID = '2D6C42E1-0C95-4E40-B792-A17E00C001BF') f ON r.FormID = f.FormID AND r.FieldID = f.FieldID) rf LEFT JOIN (select FormID, FieldID, Value from FormValues where FormID = '2D6C42E1-0C95-4E40-B792-A17E00C001BF' and UserName = '0000000000') v ON rf.FormID = v.FormID AND rf.FieldID = v.FieldID FormID FieldID ReportItem's Title Values 2D6C42E1-0C95-4E40-B792-A17E00C001BF E7A78AC7-10A4-4752-85D6-A17E00C22EF9 Question's Title user's 1st question goes here... 2D6C42E1-0C95-4E40-B792-A17E00C001BF E7A78AC7-10A4-4752-85D6-A17E00C22EF9 Question's Title user's 2nd question goes here... 2D6C42E1-0C95-4E40-B792-A17E00C001BF E7A78AC7-10A4-4752-85D6-A17E00C22EF9 Question's Title user's 2nd question goes here... 2D6C42E1-0C95-4E40-B792-A17E00C001BF 8E1FAC2A-02F1-4D0D-A3E0-A184001484D8 Answer's Title admin's answer to user's 1st question </code></pre> <p>Note: </p> <ul> <li>Empty answers are the one has not been answered (NULL).</li> <li>The result should be based upon <strong>UserName</strong> and <strong>ReportID</strong></li> <li>All IDs are GUID</li> <li>Both questions and answers are stored in FormValues table</li> </ul> <p>Maybe I should use cursor, but I'm really confused what to do. I'd highly appreciate if someone help me.</p> <p>Many thanks in advance,</p> <p>Kardo</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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