Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    sql con parametro in array

    salve,
    ho una tabella in access così formata:
    - id
    - codice
    - gruppo
    -ecc...

    ora nel campo gruppo ho una serie di informazioni del tipo:
    1,5,9,52 ( recor 1)
    5,41,66 (record 2)
    1,3,6,9 (record3)

    ora la domanda è:
    come ottengo una query che mi restituisca solo i record che hanno nel campo gruppo il carattere 1? ( nell'esempio sopre record1 e record3)
    Grazie
    marco
    Carpe diem
    Preferisco tentare che rinunziare

  2. #2
    io avrei creato un'altra tabella di corrispondenza con i gruppi... comunque, lasciando un solo campo io farei così

    1. trasformerei i valori a,b,c,d in |a|b|c|d|
    2. fare una sql="...WHERE campo LIKE '%|" & valore & "|%' ...."

  3. #3
    ci avevo pensato ma nn va bene in quanto il like mi prenderebbe sia 1| che 11| che 112|
    Carpe diem
    Preferisco tentare che rinunziare

  4. #4
    Posso farti una domanda?
    Ma quei valori numerici messi li e divisi da virgola cosa sono?
    Riferimenti ad id di qualche altra tabella?

  5. #5
    Originariamente inviato da marco1970
    ci avevo pensato ma nn va bene in quanto il like mi prenderebbe sia 1| che 11| che 112|
    no! guarda bene quello che ti ho suggerito!

  6. #6
    si sono id di altre tabelle.
    in pratica ho un menu con infiniti sottomenu e quindi nn posso usare 2 tabelle tipo categoria e sottocategoria.
    questo mi serve ad assegnare lo stesso prodotto a + categorie senza reinserirlo nuovamente
    Carpe diem
    Preferisco tentare che rinunziare

  7. #7
    ciao optime scusa per la risposta affrettata. Effettivamente è come dici tu in quanto leggi tra | |.
    ti ringrazio problema risolto
    Carpe diem
    Preferisco tentare che rinunziare

  8. #8
    Originariamente inviato da marco1970
    si sono id di altre tabelle.
    in pratica ho un menu con infiniti sottomenu e quindi nn posso usare 2 tabelle tipo categoria e sottocategoria.
    questo mi serve ad assegnare lo stesso prodotto a + categorie senza reinserirlo nuovamente

    Potevi fare una sola tabella con l'aggiunta del campo parentID.
    Le voci di primo livello avrebbero avuto parentID = 0
    tblNames
    ID - contatore
    name - testo
    parentID - numerico

    codice:
    ID     name          parentID
    1      Sport                0
    2      Cronaca           0
    3      Calcio              1
    4      Tennis              1
    5      Notizie             2
    6      Italia                5
    7      Estero              5
    8      Serie A            3
    9      Champions L.  3
    10    Roland Gar.     4
    11    Golf                  1
    12    PGA Tour         11
    E con queste funzioni costruisci il menu e la barra di navigazione:
    codice:
    <%
    set conn = server.createObject("ADODB.Connection")
    conn.open	"Provider=sqloledb; " &_
    			"Network Library=DBMSSOCN; " &_
    			"Encrypt=yes;" &_
                            "Data Source=localhost;" &_
                            "Initial Catalog=samples;" &_
                            "User Id=xxxxxx;" &_
                            "Password=xxxxxx;"
    
    page = request.serverVariables("PATH_INFO")
    
    id = request.queryString("id")
    if len(id) > 0 and isNumeric(id) then
    	id = cLng(id)
    else
    	id = 0
    end if
    
    
    function buildMenu(theID, theConn)
    	theSql = "SELECT * FROM tblNames WHERE parentID = " & theID
    		set theRs = theConn.execute(theSql)
    			if not theRs.eof then
    				response.write "<ul>" & vbCrLf
    					do until theRs.eof
    						response.write "[*]" & theRs("name") & "" & vbCrLf
    						call buildmenu(theRs("ID"), theConn)
    						response.write "" & vbCrLf
    						theRs.moveNext
    					loop
    				response.write "[/list]" & vbCrLf
    				theRs.Close
    				set theRs = nothing
    			else
    				theRs.close
    				set theRs = nothing
    			exit function
    		end if
    end function
    
    function buildNavigationBar(theID, theBaseID, theConn, byRef theNavigationBar)
    	theSql = "SELECT * FROM tblNames WHERE ID = " & theID	
    	set theRs = theConn.execute(theSql)
    		if not theRs.eof then
    				if theBaseID = theRs("ID") then
    					tempString = theRs("name") & " "
    				else
    					tempString = "" & theRs("name") & " "
    				end if
    			theNavigationBar = "&raquo; " & tempString & theNavigationBar
    			tempID = theRs("parentID")
    			theRs.close
    			set theRs = nothing
    			call buildNavigationBar(tempID, theBaseID, theConn, theNavigationBar)			
    		else
    			theRs.close
    			set theRs = nothing
    			exit function
    		end if
    end function
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>TITOLO PAGINA</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <%
    call buildMenu(0, conn)
    call buildNavigationBar(id, id, conn, navigationBar)
    response.write navigationBar
    %>
    </body>
    </html>
    <%
    conn.close
    set conn = nothing
    %>
    Provalo.

  9. #9
    ...allora premettendo che ho risolto ci tengo sempre a capire cosa mi consigliano.

    in pratica io ho un menu con infiniti sottomenu che aloro volta potranno avere infiniti sottomenu e così via.
    Il problema era: come assegno, ad esempio a 10 sottomenu diversi lo stesso prodotto senza reinserirlo?
    Grazie per il tempo che mi avete dedicato

    Ps la tabella del mio menu è formata proprio come mi hai esposto tu
    Marco
    Carpe diem
    Preferisco tentare che rinunziare

  10. #10
    In genere una "voce" ha un padre "naturale" e può avere tanti altri "padri adottivi".
    Per fare questo serve un'altra tabella di relazioni fatta in questo modo:

    tblRalations
    childID - numerico
    parentID - numerico

    Dai nomi dei campi si evince il loro scopo.

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 © 2026 vBulletin Solutions, Inc. All rights reserved.