<% 'CREATE TABLE nums(num INTEGER NOT NULL,PRIMARY KEY(num)) 'GO 'INSERT INTO nums VALUES(11) 'GO 'INSERT INTO nums VALUES(12) 'GO 'INSERT INTO nums VALUES(21) 'GO 'INSERT INTO nums VALUES(22) 'GO 'INSERT INTO nums VALUES(23) 'GO 'INSERT INTO nums VALUES(31) 'GO function query(sqlstr) Set con = Server.CreateObject("ADODB.Connection") con.Open "Provider=SQLNCLI11; Server=ARNEPC4; Database=Test; Trusted_Connection=yes;" Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sqlstr, con res = rs.GetRows() Set rs = Nothing Set con = Nothing query = res end function function getColA() getColA = query("SELECT num FROM nums WHERE num BETWEEN 10 AND 19") end function function getColB() getColB = query("SELECT num FROM nums WHERE num BETWEEN 20 AND 29") end function function getColC() getColC = query("SELECT num FROM nums WHERE num BETWEEN 30 AND 39") end function function getVal(x, i) if i <= ubound(x, 2) then getVal = x(0, i) else getVal = "" end if end function %> <% dim a, b, c a = getColA() b = getColB() c = getColC() dim n n = ubound(a, 2) if ubound(b, 2) > n then n = ubound(b, 2) end if if ubound(c, 2) > n then n = ubound(c, 2) end if %> <% dim i for i = 0 to n %> <% next %>
A B C
<%=getVal(a, i)%> <%=getVal(b, i)%> <%=getVal(c, i)%>