0

I have stored procedure to produce below result:

Result from sp and also display in html table

Currently I'm using ASP as below code to display html table as above;

if DBExecute(SQL,adoConn2,rsSQL,True) then
    while not rsSQL.eof
 <tr>
     <td>1st data</td>
     <td>2nd data</td>
     <td>3rd data</td>
     <td>4th data</td>
     <td>5th data</td>
 </tr>
    rsSQL.movenext
    wend
end i

The question is how implement rowspan for the same '1st data' in the table? So that my table should look like this;

---------------------------------
SCB0007091 | BCRP01 | 2 | 2 | 0 |
---------------------------------
SCB0007092 | EFFY   | 1 | 1 | 0 |
           ----------------------
           | BJGG01 | 5 | 5 | 0 |
           ----------------------
           | BSP401 | 3 | 3 | 0 |
---------------------------------
SCB0007093 | CGMO01 | 10| 10| 0 |
1
  • 1- sort the data based on the 1st col, 2- check the prev col data if equal to current col data in the iteration. Commented Aug 23, 2018 at 6:09

1 Answer 1

2

As stated in the comments, your SQL query should sort the data by your key column.

<%
if DBExecute(SQL, adoConn2, rsSQL, True) then

    ' go through the table once and count how many times each key column value occurs
    rowspan = server.createobject("Scripting.Dictionary")
    while not rsSQL.eof
        key = rs!column1
        if not rowspan.exists(key) then rowspan.add(key, 0)  
        rowspan(key) = rowspan(key) + 1
        rsSQL.movenext
    wend

    ' reset the recordset and build the actual table
    rsSQL.movefirst
%>
    <table>
<%
    while not rsSQL.eof
        key = rs!column1
%>
        <tr>
<%    
        ' output the first <td> only once, with the correct rowspan
        if rowspan.exists(key) then
%>
            <td rowspan="<%=rowspan(key)%>"><%=server.htmlencode(key)%></td>
<%
            rowspan.remove(key)
        end if

        ' output remaining <td>s normally
%>
            <td><%=server.htmlencode(rsSQL!column2)%></td>
            <td><%=server.htmlencode(rsSQL!column3)%></td>
            <td><%=server.htmlencode(rsSQL!column4)%></td>
            <td><%=server.htmlencode(rsSQL!column5)%></td>
        </tr>
<%
        rsSQL.movenext
    wend
%>
    </table>
<%
end if
%>
Sign up to request clarification or add additional context in comments.

1 Comment

I'm using the same concept but different implementation and its work. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.