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

    [Asp] Select Case e Sql

    Buon giorno a tutti!
    Devo estrarre dei record da un database a seconda delle variabili (IDscheda) e (q). Mi chiedevo se mai fosse possibile usare una select Case

    if (IDscheda) = "" and q <> "" then
    sql = "SELECT * FROM scheda INNER JOIN atleti ON scheda.IDuser = atleti.id WHERE ruolo = '"&q&"' LIMIT "&PrimoRs&","& pageSize
    ElseIf (IDscheda) <> "" and q = "" OR ((IDscheda) <> "" and q <> "")then

    sql = "SELECT * FROM scheda INNER JOIN atleti ON scheda.IDuser = atleti.id WHERE IDuser = '"&IDscheda&"' LIMIT "&PrimoRs&","& pageSize
    ElseIF (IDscheda) = "" and q = "" then

    sql="SELECT * FROM scheda INNER JOIN atleti ON scheda.IDuser = atleti.id WHERE complete = 'Y' LIMIT "&PrimoRs&","& pageSize
    end if

    Saluti.

  2. #2
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Si certo.
    Costruiresti di fatto una query dinamica. Al primo pezzo che sarebbe uguale per tutti aggiungeresti i dati della WHERE a seconda del valore di alcune variabili.

    Roby

  3. #3
    Grazie per aver risposto!.
    Sto cercando di fare un SELECT CASE in questo modo:

    id=Request.Querystring("id")
    q=Request.Querystring("q")

    SELECT CASE (id) come aggiungo 2 espressioni (la variabile(q))?
    Case (IDscheda) = "" and q <> ""
    sql = "SELECT * FROM scheda INNER JOIN atleti ON scheda.IDuser = atleti.id WHERE ruolo = '"&q&"' LIMIT "&PrimoRs&","& pageSize
    Case ....
    .....
    END SELECT

    E il ragionamento esatto?

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Si ma non avevo letto bene..
    Con la SELECT CASE credo tu possa analizzare una sola variabile...
    Forse in questo caso è meglio la classica IF THEN ELSE END IF

    Roby

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.