SELECT GROUP BY AND ORDER BY Sql

Asked

Viewed 146 times

0

I have two tables Tb_process and Tb_costs united by key Numeroprocesso. I need lists of their union information sorted by Urgency and Date status. When urgent, they should be listed at the top of the list.

inserir a descrição da imagem aqui

I’m not able to sort by date, from smaller to larger ex: 11/04/2019, 14/04/2019, 16/04/2019

SQL:

    @AdvogadoID int,
    @TipoCustas nvarchar(9),
    @Numero int

SELECT  TOP (@Numero)        
        Processo.NumeroProcesso, 
        Processo.GCPJ, 
        Processo.ProcessoID,
        Processo.Natureza, 
        Processo.Valor, 
        Processo.Comarca, 
        Processo.Vara,
        Custas.CustasID, 
        Custas.Descricao, 
        Custas.AdvogadoID, 
        Custas.ValorCustas, 
        Custas.DataCustas, 
        Custas.Concluida,
        Custas.DataPrazo,
        Custas.TipoCustas,
        Custas.Urgencia

FROM    Processo INNER JOIN Custas 
ON      Processo.NumeroProcesso = Custas.NumeroProcesso
WHERE   (Custas.AdvogadoID = @AdvogadoID)
AND     (Custas.TipoCustas = @TipoCustas)

ORDER BY Custas.Urgencia DESC

1 answer

3


Dear friend, I apologise if you do not understand the problem and if my answer seems innocent. You didn’t just miss:

ORDER BY Custas.Urgencia DESC, Custas.DataCustas
  • ORDER BY Costs.Urgency DESC, Costs.Timeframe was simply that!

  • 1

    Good, I hope I helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.