Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

Dynamic Query

Dynamic Query with searches on more keywords coming from different fields of a form.
>Splits the search string and for each value add a where clause to the query.


SQLQUERY="select * from db"
'read parameters
field1 = Request("field1")
field2 = Request("field2")
field3 = Request("field3")
field4 = Request("field4")
one_field=false
if field1<>"None" then
  SQLQUERY=SQLQUERY & " WHERE "
  SQLQUERY=SQLQUERY & "db.field1 = '" & field1 & "'"
  one_field = true
end if
if field2<>"None" then
  if one_field = false then
    SQLQUERY=SQLQUERY & " WHERE "
  else
    SQLQUERY=SQLQUERY & " and"
  end if
  SQLQUERY=SQLQUERY & "db.field2 = '" & field2 & "'"
  one_field = true
end if
if field3<>"None" then
  if one_field = false then
    SQLQUERY=SQLQUERY & " WHERE "
  else
    SQLQUERY=SQLQUERY & " and"
  end if
  SQLQUERY=SQLQUERY & "db.field3 = '" & field3 & "'"
  one_field=true
end if
if field4<>"None" then
  if one_field = false then
    SQLQUERY=SQLQUERY & " WHERE "
  else
    SQLQUERY=SQLQUERY & " and"
  end if
  SQLQUERY=SQLQUERY & "db.field4 = '" & field4 & "'"
end if


Download code...


Print this page


 

Inizio pagina

risorse per webmaster