Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá Amigos,
Estou com uma dificuldade em minha consulta.. preciso que ao informar o nome do Professor ela me mostre somente as aulas que ele deu no atual mês , mas ele mostra todos..
Tentei usar a função abaixo sem sucesso :
<%
varMesAtual = month(date())
strSQL = "Select * from Aulas where MONTH(ven)="& varMesAtual
Set ObjRs = cnnSearch.Execute(strSQL)
%>
Segue o código completo:
<%
Dim strURL
Dim cnnSearch
Dim rstSearch
Dim strDBPath
Dim strSQL
Dim strSearch
inicio = Timer
'#Função que tira todos os acentos das palavras
function TiraAcento(StrAcento)
for i = 1 to len(StrAcento)
Letra = mid(StrAcento, i, 1)
Select Case Letra
Case "á","Á","à","À","ã","Ã","â","Â","â","ä","Ä"
Letra = "A"
Case "é","É","ê","Ê","Ë","ë","È","è"
Letra = "E"
Case "í","Í","ï","Ï","Ì","ì"
Letra = "I"
Case "ó","Ó","ô","Ô","õ","Õ","ö","Ö","ò","Ò"
Letra = "O"
Case "ú","Ú","Ù","ù","ú","û","ü","Ü","Û"
Letra = "U"
Case "ç","Ç"
Letra = "C"
Case "ñ"
Letra = "N"
End Select
texto = texto & Letra
next
TiraAcento = textostrURL = Request.ServerVariables("URL")
strSearch = Request.QueryString("search")
%>
<title>WEB ADMIN</title>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<body bgcolor="#FFFFFF">
<link rel="stylesheet" media="screen" href="style.css" />
<table width="1" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F2FFF2">
<tr>
<td bgcolor="#FFFFFF" width="812">
<table width="515" border="0" cellpadding="2" style="border-collapse: collapse" height="1">
<tr>
<td bgcolor="#FFFFFF" height="4" colspan="2" width="667">
<p align="left">
<span style="font-size: 14pt">Relação de Aulas por Professor</span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" valign="middle" height="1" width="569">
<form action="<%= strURL %>" method="get">
<div align="left">
<b><font face="Arial" style="font-size: 8pt"> </font></b><b><font face="Arial" style="font-size: 8pt"><br>
<br>
Informe o Professor </font>
</b>
<span style="font-size: 11pt; font-weight: 400"><input type="text" placeholder="Categoria" size="55" name="search" value="<%= strSearch %>"></span><span style="font-size: 8pt"><font face="Arial" color="#008000">
</font>
</span>
<font face="Arial" color="#008000">
<input name="submit" type="submit" value="busca" style="font-size: 8 pt; font-weight: bold; background-color: #00699C; color:#FFFFFF; " /><span style="font-size: 8pt">
</span>
</font>
</div>
</form>
<p align="center">
<font face="Arial" style="font-size: 8pt">
<%
If strSearch <> "" Then
strDBPath = Server.MapPath("Noticias.mdb")
Const adUseClient = 3
Set cnnSearch = Server.CreateObject("ADODB.Connection")
cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
cnnSearch.CursorLocation = adUseClient
varMesAtual = month(date())
strSQL = "Select * from Aulas where MONTH(ven)="& varMesAtual
Set ObjRs = cnnSearch.Execute(strSQL)
strSQL = "SELECT nome,data,horario,unidade,ven,id " _
& "FROM Aulas " _
& "WHERE nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
& "OR ven LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
& "ORDER BY id;"
Set rstSearch = cnnSearch.Execute(strSQL)
intContador = rstSearch.RecordCount
%>
</font>
</p></td>
<td bgcolor="#FFFFFF" valign="top" height="1" width="94">
<p align="center">
<font face="Arial" style="font-size: 8pt"><a title="Imprimir" href="a">
<script language="JavaScript1.2">
<!--
function DoPrinting(){
if (!window.print){
alert("Use o Netscape ou Internet Explorer \n nas versões 4.0 ou superior!")
return
}
window.print()
}
//-->
</script>
</a>
</font></td>
</tr>
</table>
<p align="left">
<font face="Century Gothic" style="font-size: 8pt"><b> <font color="#6E9F4D"> </font><font color="#1D2447"> ( Foram encontradas <%=intContador%>
ocorrências )</font></b></font></p>
<div align="center" style="width: 502; height: 246">
<table width="690" border="0" cellpadding="4" cellspacing="0" bgcolor="#FFFFFF" style="border-collapse: collapse" bordercolor="#111111" height="1">
<tr>
<th width="39" bgcolor="#525252" align="left" style="border-bottom-style: none; border-bottom-width: medium" bordercolor="#99B5C0" height="21"><strong>
<font face="Arial" style="font-size: 8pt" color="#FFFFFF">Cod</font></strong></th>
<th width="627" bgcolor="#525252" align="left" style="border-bottom-style: none; border-bottom-width: medium" bordercolor="#99B5C0" height="21">
<strong><font color="#FFFFFF"><span style="font-size: 8pt">Nome do
Professor</span></font></strong></th>
<th width="627" bgcolor="#525252" align="left" style="border-bottom-style: none; border-bottom-width: medium" bordercolor="#99B5C0" height="21">
<strong><font color="#FFFFFF"><span style="font-size: 8pt">Data</span></font></strong></th>
<th width="627" bgcolor="#525252" align="left" style="border-bottom-style: none; border-bottom-width: medium" bordercolor="#99B5C0" height="21">
<strong><font color="#FFFFFF"><span style="font-size: 8pt">Horário</span></font></strong></th>
<th width="627" bgcolor="#525252" align="left" style="border-bottom-style: none; border-bottom-width: medium" bordercolor="#99B5C0" height="21">
<strong><font color="#FFFFFF"><span style="font-size: 8pt">Núcleo</span></font></strong></th>
<th width="184" bgcolor="#FFFFFF" align="left" style="border-bottom-style: none; border-bottom-width: medium" bordercolor="#99B5C0" height="21"> </th>
</tr>
<%
Do While Not rstSearch.EOF
%><font face="Century Gothic" style="font-size: 8pt"> </font>
<tr>
<%
id = Trim(rstSearch.Fields("id"))
Response.Write "<TR style='cursor=hand;' id="& id&" onclick=""consultarClick('"&id&"')""; class='"&fundo&"' "
Response.Write " onmouseover=""this.className='inputMouse';"" "
Response.Write " onmouseout=""this.className='"&fundo&"';"">"
%><font face="Century Gothic" style="font-size: 8pt"> </font>
<td width="39" align="left" style="border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:none; border-top-width:medium; border-bottom-style:solid; border-bottom-width:1" bordercolor="#6E9F4D" bgcolor="#FFFFFF" height="1"><font size="1" face="Arial"><%= rstSearch.Fields("id").Value %></font></td>
<td width="627" align="left" style="border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:none; border-top-width:medium; border-bottom-style:solid; border-bottom-width:1" bordercolor="#6E9F4D" bgcolor="#FFFFFF" height="1"><font size="1" face="Arial"><%= rstSearch.Fields("nome").Value %></font></td>
<td width="627" align="left" style="border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:none; border-top-width:medium; border-bottom-style:solid; border-bottom-width:1" bordercolor="#6E9F4D" bgcolor="#FFFFFF" height="1"><font size="1" face="Arial"><%= rstSearch.Fields("ven").Value %></font></td>
<td width="627" align="left" style="border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:none; border-top-width:medium; border-bottom-style:solid; border-bottom-width:1" bordercolor="#6E9F4D" bgcolor="#FFFFFF" height="1"><font size="1" face="Arial"><%= rstSearch.Fields("horario").Value %></font></td>
<td width="627" align="left" style="border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:none; border-top-width:medium; border-bottom-style:solid; border-bottom-width:1" bordercolor="#6E9F4D" bgcolor="#FFFFFF" height="1"><font size="1" face="Arial"><%= rstSearch.Fields("unidade").Value %></font></td>
<td width="184" align="left" style="border-style: none; border-width: medium; " bordercolor="#6E9F4D" height="1">
</td>
</tr>
<%
rstSearch.MoveNext
Loop
%><font face="Century Gothic" style="font-size: 8pt"> </font>
</table>
<p align="left">
<font face="Arial" style="font-size: 8pt">
<input type="image" src="ico_imprimir.jpg" border="0" OnClick="javascript:DoPrinting()" name="I1" alt="Imprimir"></font><p align="left"><b>
<font face="Century Gothic" style="font-size: 8pt" color="#1D2447">Sua busca foi processada em
<%response.write FormatNumber( Timer - inicio, 2 )%>
segundos.</font><font face="Century Gothic" style="font-size: 8pt" color="#6E9F4D"><br>
</font></b>
<font face="Century Gothic" style="font-size: 8pt">
<%
rstSearch.Close
Set rstSearch = Nothing
cnnSearch.Close
Set cnnSearch = Nothing
End If
%> </font>
</div></td>
</tr>
</table>
<p align="left"> </p>Olá,
Retorna o seguinte erro:
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression 'MONTH(ven)=&varMesAtual'.
Abs
Olá,
Coloquei desta forma e não retornou erro:
strSQL = "Select * from Aulas where MONTH(data)='"&varMesAtual&"'"
Porém ele mostra independente do nome que digitar na pesquisa ela mostra todos que estão cadastrados dentro da tabela no mês de fevereiro.. e não o nome de quem eu pesquisar....
Att>
Em 12/02/2018 at 23:27, chocomilki disse:
<% varMesAtual = month(date())
strSQL = "Select * from Aulas where MONTH(ven)="& varMesAtual
Set ObjRs = cnnSearch.Execute(strSQL) %>
esse trecho esta correto porem só retornará fevereiro e quando estivermos em março só retornará março... a questão é essa linha...
varMesAtual = month(date())
deveria pelo menos assim:
varMesAtual = request("campomes") ' nesse campo colocaria o número direto ou faria um combo com os meses com o value com os numeros...
Ola Gustavo,
Então na verdade ele está mostrando pra mim todos que estão no Mês Atual , mas o problema não é esse é que após incluir o código qualquer nome que digite na minha busca ele retorna todos os nomes e não o que eu digito.. ou seja se Digitar Lucas ele deveria mostrar todas as aulas de Lucas no mês de Fevereiro.. e está mostrando todos os Alunos do Mês de Fevereiro
Abs
Entendi... então está faltando mais um parametro...
strSQL = "Select * from Aulas where MONTH(ven)="& varMesAtual & " and nomealuno='Lucas*'
OBS1: sendo base access ou SQL SERVER utilize * para busca qualquer Lucas se for Postgresql utilize %Gustavo
Acrescentei o parâmetro retornou erro interno..
O servidor encontrou um erro interno ou configuração incorreta e não pôde completar sua solicitação. Entre em contato com o administrador do servidor para informar a hora em que ocorreu o erro e de qualquer coisa que você tenha feito que possa ter causado o erro. Mais informações sobre esse erro podem estar disponíveis no registro de erros do servidor.
qual é o nome do campo do aluno?
campo aluno é NOME ..
me mostre como ficou a SQL...
strSQL = "Select from Aulas where MONTH(data)="& varMesAtual & " and nome=''
do jeito que está vai dar erro mas se estivesse correto retornaria todos os alunos...
Tente assim:
strSQL = "Select * from Aulas where MONTH(data)="& varMesAtual & " and nome Like 'Lucas*'"
Detalhe: tem que ter lucas no cadastro... rsrs...Agora não retornou erro , porém mostra independe se é mês Fevereiro , Janeiro etc.. rsssss
varMesAtual = month(date())
strSQL = "Select from Aulas where MONTH(data)="& varMesAtual & " and nome Like 'Kleber'"
coloque o mes fixo... e vamos colocar o ano também... senão pode pegar dos anos anteriores também...
strSQL = "Select from Aulas where MONTH(data)=2 and year(data)=2018 and nome Like 'Kleber'"
Olha como ficou ele completo
<%
If strSearch <> "" Then
strDBPath = Server.MapPath("Noticias.mdb")
Const adUseClient = 3
Set cnnSearch = Server.CreateObject("ADODB.Connection")
cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
cnnSearch.CursorLocation = adUseClient
varMesAtual = month(date())
strSQL = "Select * from Aulas where MONTH(data)=2 and year(data)=2018 and nome Like 'Kleber*'"
strSQL = "SELECT nome,data,horario,unidade,ven,id " _
& "FROM Aulas " _
& "WHERE nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
& "OR nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
& "ORDER BY id;"
Set rstSearch = cnnSearch.Execute(strSQL)
intContador = rstSearch.RecordCount
%>
E mostra mês anterior tb.. rssss
>
3 minutos atrás, chocomilki disse:
strSQL = "Select * from Aulas where MONTH(data)=2 and year(data)=2018 and nome Like 'Kleber*'"
strSQL = "SELECT nome,data,horario,unidade,ven,id " _ & "FROM Aulas " _ & "WHERE nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _ & "OR nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _ & "ORDER BY id;"
a variavel strSQL só pode ter uma instrução antes da execução senão somente a última que é feita... remova essa..
strSQL = "SELECT nome,data,horario,unidade,ven,id " _ & "FROM Aulas " _ & "WHERE nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _ & "OR nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _ & "ORDER BY id;"Gustavo,
Mas este trecho é o que pesquisa o nome do Aluno...
strSQL = "SELECT nome,data,horario,unidade,ven,id " _ & "FROM Aulas " _ & "WHERE nome LIKE '%" &TiraAcento(Replace(strSearch, "'", "''")) & "%' " _ & "OR nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _ & "ORDER BY id;"
desse jeito não pode... na sql
strSQL = "Select * from Aulas where MONTH(data)=2 and year(data)=2018 and nome Like 'Kleber*'"
já tem o mês e o nome que você quer... não precisa de uma outra e mesmo se precisasse não seria desse jeito... remova essa segunda e rode a página...Ola Gustavo,
Não entendi...
Ola Gustavo,
Não entendi...
strSQL = "Select from Aulas where MONTH(data)=2 and year(data)=2018 and nome Like 'Kleber'"
set rstSearch = cnnSearch.Execute(strSQL)
Execute somente essa SQL vai ter que te retornar se o kleber participou da aula no mês de fevereiro se não retornar nada então o kleber não participou... ai tente outro aluno...
Ola
Tirei Mas desse forma não vai retorna nada pois a Sql que faz a consulta é a outra....
Abs
>
On 2/22/2018 at 7:29 PM, chocomilki said:
Ola
Tirei Mas desse forma não vai retorna nada pois a Sql que faz a consulta é a outra....
Abs
>
Quote
strSQL = "Select * from Aulas where MONTH(data)=2 and year(data)=2018 and nome Like 'Kleber*'"
strSQL = "SELECT nome,data,horario,unidade,ven,id " _
& "FROM Aulas " _
& "WHERE nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
& "OR nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
& "ORDER BY id;"
Set rstSearch = cnnSearch.Execute(strSQL)
Qual a necessidade dessas duas consultas?
Em ASP caso quando coloque condições entre as execuções de SQL somente a ultima será executada, ou entao voce atribui nomes diferentes a suas strings que armazenam a query e armazene elas em diferentes RecordSets,
Mas acho que que pelo que entendi voce ta fazendo um select completo no banco com o mes como paramentro de busca e no outro select voce esta tendo buscar desse ultimo select somente os nomes que foram pesquisados!! Isso nao é necessario se utilizar somente a primeira com os paramentros que o Gustavo te passou, ate porque esses seus selects nao vao funcionar como acho que esta pensando!!Olá Maurilio,
A Consulta abaixo é que utilizo para pesquisar o nome do aluno correto...
strSQL = "SELECT nome,data,horario,unidade,ven,id " _
& "FROM Aulas " _
& "WHERE nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
& "OR nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
& "ORDER BY id;"
Isso ja funcionava normalmente o que quero fazer é **acrescentar mais um critério para que depois de Pesquisar** o nome do** Aluno **ele me mostre somente os registro do **MÊS ATUAL,** isso que não estou conseguindo fazer ok..
AbsMaurilio e choco... tem que se dever a somente uma SQL ... colocar duas instruções uma seguida da outra sem executar somente se executada a última...
outro detalhe desse trecho...
& "WHERE nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
& "OR nome LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
não entendi... por que o OR com mesmo campo e parametro... outro detalhe trocar apóstrofo por dois apóstrofos não vai funcionar acredito que quisesse colocar aspas duas que ficaria assim: TiraAcento(Replace(strSearch, "'", chr(34) )) ... porém a sql funciona com aspas simples ou aspas duplas... mas por desencargo de consciência pode substituir...
Ainda insisto que deve insistir nessa unica SQL
strSQL = "Select from Aulas where MONTH(data)=2 and year(data)=2018 and nome Like 'Kleber'"
set rstSearch = cnnSearch.Execute(strSQL)
pois nela você tem o filtro do mês do ano também é importante senão buscará o mês de fevereiro de todos os anos... e também filtrando o nome do aluno....
não sei qual seu banco de dados mas se não estiver retornando nada mesmo tendo registros que deveriam vir pode colocar ilike ao invés de like pois vai ignorar o Case Sensitive que são as letras maiúsculas ou minúsculas...
Ola,