Arrange column Period in SQL in ascending or descending order

0

Personal I have the following question / problem

I'm doing a select on some accounts and organized by filename, but I need to organize for the period but I'm not getting it because it's not a single date. I can not use the creation date.

My select:

SELECT DISTINCT Periodo, Nome_Arquivo, Tel FROM Arquivos WHERE Id_Cliente = 999 ORDER BY Periodo

And what works for me is this:

23/01/2016 até 22/02/2016   teste73xczx.txt 11 9999-9999
23/01/2017 até 22/02/2017   teste1773zx.txt 11 9999-9999
23/02/2016 até 22/03/2016   testezxczxc.txt 11 9999-9999
23/03/2016 até 22/04/2016   testezxczx.txt  11 9999-9999

I would like to leave it growing but even putting it, then it would look like this

23/01/2016 até 22/02/2016   teste73xczx.txt 11 9999-9999
23/02/2016 até 22/03/2016   testezxczxc.txt 11 9999-9999
23/03/2016 até 22/04/2016   testezxczx.txt  11 9999-9999
23/01/2017 até 22/02/2017   teste1773zx.txt 11 9999-9999

Would anyone have any ideas?

Perhaps with more example, the total result of the id: Periods:

23/01/2016 até 22/02/2016
23/01/2017 até 22/02/2017
23/02/2016 até 22/03/2016
23/03/2016 até 22/04/2016
23/04/2016 até 22/05/2016
23/05/2016 até 22/06/2016
23/06/2016 até 22/07/2016
23/07/2016 até 22/08/2016
23/08/2016 até 22/09/2016
23/09/2016 até 22/10/2016
23/10/2016 até 22/11/2016
23/11/2016 até 22/12/2016
23/12/2016 até 22/01/2017
    
asked by anonymous 08.03.2017 / 18:58

1 answer

0

I separated the date of the period by the month and by the year so I got an organized construction of the table

 SELECT DISTINCT Periodo, Nome_Arquivo,
    LTRIM(SUBSTRING(Periodo,19,2)) as MesFinal,
    LTRIM(SUBSTRING(Periodo,22,4)) as AnoFinal,
    Tel FROM Vox_Arquivos WHERE Id_Cob_Clientes = 9999 order by AnoFinal desc,MesFinal desc

result

23/01/2017 até 22/02/2017
23/12/2016 até 22/01/2017
23/11/2016 até 22/12/2016
23/10/2016 até 22/11/2016
23/09/2016 até 22/10/2016
23/08/2016 até 22/09/2016
23/07/2016 até 22/08/2016

Part of the idea of separation came from Antonio Alexandre's comment (First comment), thank you!

    
08.03.2017 / 20:13