USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  Como usar o Select Max??
Paula
não registrado
Postada em 18/03/2005 08:47 hs   
Estou querendo obter o ultimo numero de chamada de uma determinada turma, alguém sabe como usar essa Query:
 
.Open "Select Max(Chamada) From ALUNOS Where codTurma='" & cmbTurma.Text & "'"
 
No lugar de:
 
.Open "Select * From ALUNOS Where codTurma='" & cmbTurma.Text & "' Order By Chamada Desc"
 
Estou usando ADO e o código que estou usando é esse:
 
Public Sub CarregarChamada()
Dim rstDados As ADODB.Recordset
Set rstDados = New ADODB.Recordset
With rstDados
    .ActiveConnection = Con_Regular
    .CursorLocation = adUseClient
    .CursorType = adOpenDynamic
    .LockType = adLockOptimistic
    .Source = "ALUNOS"
    .Open "Select * From ALUNOS Where codTurma='" & cmbTurma.Text & "' Order By Chamada Desc"
End With
If rstDados.RecordCount <> 0 Then
    cChamada = rstDados!Chamada + 1
    txtNumero.Text = cChamada
Else
    txtNumero.Text = ""
End If
rstDados.Close
Set rstDados = Nothing
End Sub
 
 
Agradeço desde já!!!Emoções
     
Mateus
AMADORA
PT - PORTUGAL
Postada em 18/03/2005 09:19 hs            
Eis um exemplo:
 

Public Function ObterCodigo() As String

 

Dim strCod As String, intMaxCod As Integer

 

Set rstMovimentos = New ADODB.Recordset

 

rstMovimentos.CursorLocation = adUseServer

rstMovimentos.Open "SELECT max(id_movimento)from tMovimentos where mid(tmovimentos.id_movimento,1,4)= '" & inicio & "'", dbDados, adOpenKeyset, adLockReadOnly, adCmdText

 

If IsNull(rstMovimentos.Fields(0)) Then

   ant = inicio & "000000"

   ObterCodigo = ant + 1

Else

ant = rstMovimentos.Fields(0).Value

ObterCodigo = ant + 1

 

End If

 

Set rstMovimentos = Nothing

 

End Function

 


João Mateus

Se precisar de ajuda extra, visite:

http://joaomateus.planetaclix.pt

     
Paula
não registrado
Postada em 18/03/2005 09:34 hs   
Obrigada Mateus, vou testar aqui pra ver se dá certo!!Emoções
     
Página(s): 1/1    


Seu Nome:

Seu eMail:

ALTERAR PARA MODO HTML
Mensagem:

[:)] = 
[:P] = 
[:(] = 
[;)] = 

HTML DESLIGADO

     
 VOLTAR

  



CyberWEB Network Ltda.    © Copyright 2000-2025   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página