Jump to content
Fórum Script Brasil
  • 0
Sign in to follow this  
Jony Walker

Mesma Página Mas Outro Problema

Question

Estou montando uma página que mostra resultados de uma pesquisa... o usuário pode preencher um ou até quatro campos para fazer a consulta. Mas quando um campo só é preenchido, ele acusa erro, dizendo há erro de sintaxe na cláusula WHERE, pois quando vai um resultado só o campo sai vazio.

Eis o código da pesquisa:

Dim varEsp, varReg, varConv, varNom

Dim rs, sqlCon, varSql

Dim varNN, varEE, varCC, varRR

varNom = request.form("name")

if trim(varNom) = "" then

varNom = request.querystring("name")

end if

varEsp = request.form("esp")

if trim(varEsp) = "" then

varEsp = request.querystring("esp")

end if

varReg = request.form("regiao")

if trim(varReg) = "" then

varReg = request.querystring("regiao")

end if

varConv = request.form("conven")

if trim(varConv) = "" then varConv = request.querystring("conven")

PagAtual = request.querystring("PagAtual") 'página atual

if varNom <> "" then

busca=split(varNom,chr(32))

dim onde

for x = 0 to Ubound(busca)

  if x > 0 then

     varNN = varNN & " and "

  end if

  varNN = varNN & "nome like '%" & busca(x) & "%'"

next

end if

if varEsp <> "" then

varEE = " espec = '" & varEsp & "' OR espec2 = '" & varEsp & "' OR espec3 = '" & varEsp & "' "

else

varEE = ""

end if

if varReg <> "" then

varRR = " regiao = '" & varReg & "' "

else

varRR = ""

end if

if varConv <> "" then

varCC = varConv & " = true OR outro = '" & varConv & "' "

else

varCC = ""

end if

if varNN <> "" AND varEE = "" AND varRR = "" AND varCC = "" then '1

varSql = varNN

end if

if varNN <> "" AND varEE <> "" AND varRR = "" AND varCC = "" then '2

varSql = varNN & " AND " & varEE

end if

if varNN <> "" AND varEE = "" AND varRR <> "" AND varCC = "" then '3

varSql = varNN & " AND " & varRR

end if

if varNN <> "" AND varEE = "" AND varRR = "" AND varCC <> "" then '4

varSql = varNN & " AND " & varCC

end if

if varNN <> "" AND varEE <> "" AND varRR <> "" AND varCC = "" then '5

varSql = varNN & " AND " & varEE & " AND " & varRR

end if

if varNN <> "" AND varEE <> "" AND varRR = "" AND varCC <> "" then '6

varSql = varNN & " AND " & varEE & " AND " & varCC

end if

if varNN <> "" AND varEE = "" AND varRR <> "" AND varCC <> "" then '7

varSql = varNN & " AND " & varRR & " AND " & varCC

end if

if varNN = "" AND varEE <> "" AND varRR = "" AND varCC = "" then '8

varSql = varEE

end if

if varNN = "" AND varEE <> "" AND varRR <> "" AND varCC = "" then '9

varSql = varEE & " AND " & varRR

end if

if varNN = "" AND varEE <> "" AND varRR = "" AND varCC <> "" then '10

varSql = varEE & " AND " & varCC

end if

if varNN = "" AND varEE = "" AND varRR <> "" AND varCC = "" then '11

varSql = varRR

end if

if varNN = "" AND varEE = "" AND varRR <> "" AND varCC <> "" then '12

varSql = varRR & " AND " & varCC

end if

if varNN <> "" AND varEE = "" AND varRR = "" AND varCC = "" then '13

varSql = varCC

end if

if varNN <> "" AND varEE <> "" AND varRR <> "" AND varCC <> "" then '14

varSql = varNN & " AND " & varEE & " AND " & varRR & " AND " & varCC

end if

if varNN = "" AND varEE = "" AND varRR = "" AND varCC = "" then '15

response.write("Não estou recebendo as informações que preciso.")

response.end

end if

Set Conn = Server.CreateObject("adodb.connection")

DSNtest = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("./guia.mdb")

Conn.Open DSNtest

Set RS = Server.CreateObject("ADODB.Recordset") 'acrescentei por causa da paginação

sqlCon = " SELECT * FROM doutores WHERE " & varSql & " ORDER BY id "

response.write sqlCon & "&nbsp;" & varEE & "&nbsp;" & varNN & "&nbsp;" & varCC & "&nbsp;" & varRR

response.end

RS.Open sqlCon, conn, 3

Por exemplo, se você pesquisar pelo nome JOAO, ele escreve a varNN impressa

(nome like %JOAO%) mas ela não aparece dentro da var de query

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  



  • Forum Statistics

    • Total Topics
      148576
    • Total Posts
      644276
×
×
  • Create New...