Do I need to split the "varchar" response series so that it appears as a new line when creating a DataTable?

What I need to do is accept the answers in the form of an online questionnaire stored in the database and display them as a table on the website that has been completed so far and looks like this:

    ||User Id |Group   | Q1                 | Q2            | Q3    | Q4   |...
    | 1234    |no group| 30/06/14, 25/08/14,| gs,gm, cl&h   | either|s1    |...
    |         |        | 27/07/14           |               |       |      |...

Now I need to display existing data in a new way. The information in the cells should be divided so that where there are several bits of information in the cell, a new line is created. Not sure if the best way to describe this is, but using the above, I want it to look like this:

||User Id |Group   | Q1      | Q2   | Q3    | Q4   |...
| 1234    |no group| 30/06/14| gs   | either|s1    |...
| 1234    |no group| 25/08/14| gm   | either|s1    |...
| 1234    |no group| 27/07/14| cl&h | either|s1    |...

In principle, the same UserID, Group, etc., but each other Q1, Q2, etc., should be used in each row.

This is the code that I have used so far to achieve the top example.

'
' sql to get data
    sql = "select * from TABLE where (datestamp > '" & startDate & "') AND (datestamp < '" & endDate & "') ORDER BY datestamp"

Set fieldTitles = CreateObject("Scripting.Dictionary")
fieldTitles.Add "userID", "User ID"
fieldTitles.Add "grp", "Group"
fieldTitles.Add "q1", "Q1"
fieldTitles.Add "q2", "Q2"
fieldTitles.Add "q3", "Q3"
fieldTitles.Add "q4", "Q4"
fieldTitles.Add "q5", "Q5"
fieldTitles.Add "q6", "Q6"
fieldTitles.Add "q7", "Q7"
fieldTitles.Add "q8", "Q8"
fieldTitles.Add "q9", "Q9"
fieldTitles.Add "qOrder1", "qOrder1"
fieldTitles.Add "qOrder2", "qOrder2"
fieldTitles.Add "qOrder3", "qOrder3"
fieldTitles.Add "qOrder4", "qOrder4"
fieldTitles.Add "datestamp", "Date Stamp"
fieldTitles.Add "Qid", "Qid"
fieldTitles.add "y5grp", "Year 5 Group"

' get the table html
dataString = createDataTableSQL(fieldTitles, sql, "")

, "Left (string, length)", , , (, Q2). - ?

+4
1

, , , , , , , ,

SELECT
DISTINCT ROWID,
trim(
regexp_substr(Q2, '[^,]+', 1, LEVEL)
) decoded
FROM
(
select
'1234' as USER_ID,
'NO GROUP' as "GROUP",
'30/06/14, 25/08/14, 27/07/14' as Q1,
'qs,gm, cl&h' as Q2,
'either' as Q3,
's1' as Q4
from
dual
) X CONNECT BY trim(
regexp_substr(Q2, '[^,]+', 1, LEVEL)
) IS NOT NULL
ORDER BY
ROWID;
+1

Source: https://habr.com/ru/post/1527944/


All Articles