Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 15
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    1,183

    Interrompere stringa sql

    Ciao a tutti
    come faccio a mandare a capo questa stringa sql ?


    codice:
    dim objcmd as new oledbdataadapter ("Select * from reception_0 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" union Select * from reception_1 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" union Select * from reception_2 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" union Select * from reception_3 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" union Select * from reception_4 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" union Select * from reception_5 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" union Select * from reception_6 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" union Select * from reception_7 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" order by tessera desc, datas desc ", objconn)
    Ultima modifica di djciko; 27-07-2020 a 09:21
    victor
    ----------------------

  2. #2

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    1,183
    grazie :-)
    victor
    ----------------------

  4. #4
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    in effetti ho sentito anch'io questa necessità. Che io sappia (ma sono ai livelli di vs2010) non si può fare, se non come ti ha consigliato Optime.

    Comunque, io trovo molta difficoltà a comporre stringhe lunghe con variabili, come fai te:

    "Select * from reception_0 where tessera >="& datainizio2***

    Io preferisco usare string.format().

    Naturalmente quando non si usano i parametri.
    Ultima modifica di djciko; 27-07-2020 a 09:18
    Pietro

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    1,183
    oggi ho provato a far cosi e funziona (con mssql)

    in pratica tutta la stringa sql la metto dentro una variabile


    dim lasele as string=" Select * from reception_0 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" "

    lasele=lasele & " union Select * from reception_1 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" "
    lasele=lasele & " union Select * from reception_2 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" "
    lasele=lasele & " union Select * from reception_3 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" "
    lasele=lasele & " union Select * from reception_4 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" "
    lasele=lasele & " union Select * from reception_5 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" "
    lasele=lasele & " union Select * from reception_6 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" "
    lasele=lasele & " union Select * from reception_7 where tessera >="& datainizio2 &" and tessera <="& datafine2 &" "
    lasele=lasele & " order by tessera desc, datas desc "



    cosi mi sono trovato comodo
    anche se ancora oggi, dopo vari scervellamenti, ho realizzato una funzione che elimina gli union e seleziona dinamicamente tutte le tabelle di un db


    fatemi sapere se vi puo' interessare
    victor
    ----------------------

  6. #6
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    il tuo codice è sbagliato. Dovresti seguire di più i link che ti hanno passato.
    Per esempio, questo codice:
    codice:
    cmd.CommandText = _ 
       "SELECT * FROM Titles JOIN Publishers " _
        & "ON Publishers.PubId = Titles.PubID " _
        & "WHERE Publishers.State = 'CA'"
    non è stato reso come:
    codice:
    cmd.CommandText = ""
    cmd.CommandText = cmd.CommandText & "SELECT * FROM Titles JOIN Publishers "
    cmd.CommandText = cmd.CommandText & "ON Publishers.PubId = Titles.PubID "
    cmd.CommandText = cmd.CommandText & "WHERE Publishers.State = 'CA'"
    I motivi? ottimizzazione delle stringhe
    Pietro

  7. #7
    anche creare una tabella per reception non mi pare un granché efficiente...

  8. #8
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    1,183
    Ciao ragazzi grazie per l'aiuto
    non capisco molto cosa intendete per poco efficiente.

    Attualmente il programma sta funzionando con la sql sopra riportata.
    E, a mio umile avviso, e' molto efficiente.
    Velocissimo e senza nessun intoppo.

    Gestisce contemporaneamente 8 reception. Con un flusso totale di circa 8000 persone al giorno.

    Secondo me ' efficiente.
    Pero' apprezzo la vostra considerazione

    grazie
    victor
    ----------------------

  9. #9
    UNA sola tabella con IdReception che indica la reception interessata. Vedrai che ti semplifica di molto tante elaborazioni; per esempio la query di cui sopra diventa semplicemente

    dim lasele as string="Select * from receptions where tessera >=" & datainizio2 & " and tessera <=" & datafine2 & " order by tessera desc, datas desc"

  10. #10
    pensa se devi aggiungere o togliere una reception: per come fai tu ti tocca ripassare tutte le query

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