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

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  Select para ranking
Irenko
BELO HORIZONTE
MG - BRASIL
Postada em 18/04/2008 16:03 hs            
TbResumo.Open "SELECT Distinct OS, Sum(Quant*Unit) AS Total  FROM Dados  GROUP BY OS ORDER BY Sum(Quant*Unit) DESC", BancoSobra, adOpenDynamic, adLockOptimistic

Com a query acima eu busco a OS com o maior valor e apresento o resultado. Acontece o seguinte, tenho as OS:

135421 - 10.000,00
135433 - 12.500,00
135444 -  1.000,00
135466 -  1.500,00

Bom acima no ranking esta a OS 135433 com 12.500,00 porem todas são do grupo (1354), como faria para buscar os grupos identicos e somar seus valores pesquisando os quatro primeiros dígitos e dando o resultado de 25.000,00?


Segue abaixo o código completo:

Sub TelaIndice()
AtivaIcon
Dim textranking As Integer
textranking = 3
Set TbResumo = New ADODB.Recordset
TbResumo.Open "SELECT Distinct OS, Sum(Quant*Unit) AS Total  FROM Dados  GROUP BY OS ORDER BY Sum(Quant*Unit) DESC", BancoSobra, adOpenDynamic, adLockOptimistic

Do While Not TbResumo.EOF

If textranking = 3 Then

    Label92.Caption = TbResumo("OS")

    Label105.Caption = Format(TbResumo("Total"), "#,##0.00")

End If
If textranking = 2 Then

    Label93.Caption = TbResumo("OS")

    Label106.Caption = Format(TbResumo("Total"), "#,##0.00")

End If
If textranking = 1 Then

    Label94.Caption = TbResumo("OS")

    Label107.Caption = Format(TbResumo("Total"), "#,##0.00")

End If
If textranking = 0 Then

    Label95.Caption = TbResumo("OS")

    Label108.Caption = Format(TbResumo("Total"), "#,##0.00")

End If
textranking = (textranking - 1)

TbResumo.MoveNext
Loop

'Fecha recordset
TbResumo.Close
Set TbResumo = Nothing
Call Gerar
End Sub
     
Rogerio.
não registrado
ENUNCIADA !
Postada em 18/04/2008 16:28 hs   
Olá, se entendi, seria assim :
 
SELECT Distinct SUBSTRING(OS,1,4) OS, Sum(Quant*Unit) AS Total  FROM Dados  GROUP BY OS ORDER BY Sum(Quant*Unit) DESC
 
Se o campo OS for numérico então :
 
SELECT Distinct SUBSTRING(CAST(OS+1000000  AS CHAR),2,5) OS, Sum(Quant*Unit) AS Total  FROM Dados  GROUP BY OS ORDER BY Sum(Quant*Unit) DES
 
Até,
 
Rogério.
   
Irenko
BELO HORIZONTE
MG - BRASIL
Postada em 18/04/2008 16:48 hs            
Esse SUBSTRING(OS,1,4) eu não conheço, coloquei e deu erro. Meu banco é access e uso ADO.
     
Página(s): 1/1    

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