0
Currently this ordained
3.1
3.10
3.11
3.2
3.3
3.4
...
3.9
and should stay:
3.1
3.2
3.3
3.4
...
3.9
3.10
3.11
script:
SELECT GCD_Tid,
GCD_Ordem,
GCD_Nome,
GCD_GCD_TidGrupoContasDre,
[1],
[2],
[3],
[4],
[5],
[6],
[7],
[8],
[9],
[10],
[11],
[12]
FROM
(
SELECT mes,
valor,
GCD_Tid,
GCD_Ordem,
GCD_Nome,
GCD_GCD_TidGrupoContasDre
FROM GRUPO_CONTAS_DRE GCD
LEFT JOIN PLANO_CONTAS PCT ON GCD.GCD_Tid = PCT.PCT_GCD_TidGrupoContasDre
OUTER APPLY
(
SELECT SUM(CASE
WHEN CPR_TipoConta = 'P'
THEN ISNULL(CPR_ValorAReceber, 0) * -1
ELSE ISNULL(CPR_ValorAReceber, 0)
END) AS valor,
DATEPART(MONTH, cpr.CPR_DataVencimento) AS mes
FROM CONTAS_PAGARRECEBER CPR(READUNCOMMITTED)
WHERE PCT_Tid = cpr.CPR_PCT_TidPlanoContas
AND YEAR(cpr.CPR_DataVencimento) = 2020
GROUP BY CPR_DataVencimento
) cpr
) AS contas PIVOT(SUM(valor) FOR mes IN([1],
[2],
[3],
[4],
[5],
[6],
[7],
[8],
[9],
[10],
[11],
[12])) AS PivotTable
ORDER BY RTRIM(LTRIM(GCD_Ordem))
I tried many ways and could not, could give me a light?
You want to sort by integer numbers, but you are ordering strings.
– Danizavtz
If I make ordering by integer numbers it stays the same way, I would like it to make ordering before the first point and so on.
– Eduardo Nogueira
It is impossible for a numerical sorting to be in the same way as a sorting as text for the given example. Maybe you are not converting your account code to numeric properly. Ex. 2.3.15.7 must be converted to 02003015007 and then ordered.
– anonimo
Could you give me an example of what I could do?
– Eduardo Nogueira
One solution is to create a sort column in the table , laborious but the sql gets "clean"
– Motta