Visualizzazione dei risultati da 1 a 3 su 3

Discussione: semplificare query

  1. #1
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427

    semplificare query

    è possibile trovare un modo più "elegante" per estrarre questi dati??

    codice:
    <%  Set rs_s = Server.CreateObject("ADODB.Recordset")
       	strSQL="SELECT id1,id2,id3,id4,id5 FROM preventivi WHERE idprev="& request("idprev")&"  "
    	rs_s.open strsql, conn	
    	if rs_s.eof then
    	rs_.close
    	set rs_s = Nothing
    	else
    	If rs_s("id1")<>"" then
    	Set rs_1 = Server.CreateObject("ADODB.Recordset")
       	strSQL="SELECT id, tipo, descr_suppl,quota_sc FROM supplementi WHERE id="& rs_s("id1")&" "
    	rs_1.open strsql, conn
    	quota1=rs_1("quota_sc")
    	tipo1=rs_1("tipo")
    	descr1=rs_1("descr_suppl")
    	id1=rs_1("id")
    	rs_1.close
    	set rs_1 = nothing
    	end if
    	If rs_s("id2")<>"" then
    	Set rs_2 = Server.CreateObject("ADODB.Recordset")
       	strSQL="SELECT id, tipo, descr_suppl,quota_sc FROM supplementi WHERE id="& rs_s("id2")&" "
    	rs_2.open strsql, conn
    	quota2=rs_2("quota_sc")
    	tipo2=rs_2("tipo")
    	descr2=rs_2("descr_suppl")
    	id2=rs_2("id")
    	rs_2.close
    	set rs_2 = nothing
    	end if
    	
    	If rs_s("id3")<>"" then
    	Set rs_3 = Server.CreateObject("ADODB.Recordset")
       	strSQL="SELECT id, tipo, descr_suppl,quota_sc FROM supplementi WHERE id="& rs_s("id3")&" "
    	rs_3.open strsql, conn
    	quota3=rs_3("quota_sc")
    	tipo3=rs_3("tipo")
    	descr3=rs_3("descr_suppl")
    	id3=rs_3("id")
    	rs_3.close
    	set rs_3 = nothing
    	end if
    	
    	If rs_s("id4")<>"" then
    	Set rs_4 = Server.CreateObject("ADODB.Recordset")
       	strSQL="SELECT id, tipo, descr_suppl,quota_sc FROM supplementi WHERE id="& rs_s("id4")&" "
    	rs_4.open strsql, conn
    	quota4=rs_4("quota_sc")
    	tipo4=rs_4("tipo")
    	descr4=rs_4("descr_suppl")
    	id4=rs_4("id")
    	rs_4.close
    	set rs_4 = nothing
    	end if
    	
    	If rs_s("id5")<>"" then
    	Set rs_5 = Server.CreateObject("ADODB.Recordset")
       	strSQL="SELECT id, tipo, descr_suppl,quota_sc FROM supplementi WHERE id="& rs_s("id5")&" "
    	rs_5.open strsql, conn
    	quota5=rs_5("quota_sc")
    	tipo5=rs_5("tipo")
    	descr5=rs_5("descr_suppl")
    	id5=rs_5("id")
    	rs_5.close
    	set rs_5 = nothing
    	end if
    	%>
    
    mostro record...

  2. #2
    Moderatore di JavaScript L'avatar di br1
    Registrato dal
    Jul 1999
    Messaggi
    19,998
    SELECT id1,id2,id3,id4,id5,
    s1.tipo as tipo1, s1.descr_suppl as descr1, s1.quote_sc as quota1,
    s2.tipo as tipo2, s2.descr_suppl as descr2, s2.quote_sc as quota2,
    s3.tipo as tipo3, s3.descr_suppl as descr3, s3.quote_sc as quota3,
    s4.tipo as tipo4, s4.descr_suppl as descr4, s4.quote_sc as quota4,
    s5.tipo as tipo5, s5.descr_suppl as descr5, s5.quote_sc as quota5
    FROM
    ((((preventivi
    left join supplementi as s1 on preventivi.id1=s1.id)
    left join supplementi as s2 on preventivi.id2=s2.id)
    left join supplementi as s3 on preventivi.id3=s3.id)
    left join supplementi as s4 on preventivi.id4=s4.id)
    left join supplementi as s5 on preventivi.id5=s5.id
    WHERE preventivi.idprev="& request("idprev")&" "

    da verificare... scritta al volo

    ciao
    Il guaio per i poveri computers e' che sono gli uomini a comandarli.

    Attenzione ai titoli delle discussioni: (ri)leggete il regolamento
    Consultate la discussione in rilievo: script / discussioni utili
    Usate la funzione di Ricerca del Forum

  3. #3
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    <% Set rs_r = Server.CreateObject("ADODB.Recordset")
    SQL= "SELECT id1,id2,id3,id4,id5,"&_
    "s1.tipo as tipo1, s1.descr_suppl as descr1, s1.quote_sc as quota1,"&_
    "s2.tipo as tipo2, s2.descr_suppl as descr2, s2.quote_sc as quota2,"&_
    "s3.tipo as tipo3, s3.descr_suppl as descr3, s3.quote_sc as quota3,"&_
    "s4.tipo as tipo4, s4.descr_suppl as descr4, s4.quote_sc as quota4,"&_
    "s5.tipo as tipo5, s5.descr_suppl as descr5, s5.quote_sc as quota5"&_
    "FROM "&_
    "((((preventivi "&_
    "left join supplementi as s1 on preventivi.id1=s1.id) "&_
    "left join supplementi as s2 on preventivi.id2=s2.id) "&_
    "left join supplementi as s3 on preventivi.id3=s3.id) "&_
    "left join supplementi as s4 on preventivi.id4=s4.id) "&_
    "left join supplementi as s5 on preventivi.id5=s5.id "&_
    " WHERE preventivi.idprev="& request("idprev")&" "
    rs_r.open sql, conn
    %>

    Tipo di errore:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
    [Microsoft][Driver ODBC Microsoft Access] L'istruzione SELECT include una parola riservata o un argomento scritto in modo errato o mancante oppure la punteggiatura non è corretta .
    /inc/suppl.asp, line 126

    il bello è che devo estrarre in teoria tutti i record da supplementi

    strSQL="SELECT * FROM supplementi WHERE codoff="& request("codoff")&" and attiva=true and id IN (" & Request("id") & "); "

    e checckare solo quelli salvati in preventivi...
    id1
    id2
    id3
    id4
    id5

    è possibile che i campi "id" siano pieni fino al id3 come al id5
    forse la cosa si può semplificare di molto.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.