scusa se rispondo solo adesso ma dovevo finire dei lavori...
per fare questa versione potresti fare così
codice:
query = "SELECT * FROM strutture ORDER BY id_struttura,sub_1,sub_2,sub_3,sub_4,sub_5"
set rs = server.CreateObject("ADODB.Recordset")
rs.Open query,Conn,3,3
if not rs.EOF then
set dic = Server.CreateObject("Scripting.Dictionary")
dic.Add "livello0",0
dic.Add "livello1",0
dic.Add "livello2",0
dic.Add "livello3",0
dic.Add "livello4",0
dic.Add "livello5",0
livello=1
id = 0
oldId=0
do while not rs.EOF
id=id+1
if livello<=5 then
if rs("sub_" & livello)>0 then
dic("livello" & livello) = oldId
livello=livello+1
end if
end if
if livello>1 then
if rs("sub_" & (livello-1))=0 then
for i=livello-1 to 1 step -1
if rs("sub_" & i)=0 then
livello=i
end if
next
end if
end if
Response.Write "Tree[Tree.length] = """ & id & "|" & dic("livello" & (livello-1)) & "|" & rs("nome_struttura") & " " & rs("id_struttura")
for i=1 to 4
Response.Write "." & rs("sub_" & i)
next
Response.Write "|#"";" & vbCrlf
oldId=id
rs.MoveNext
loop
end if
fammi sapere se va bene