1
I have the following query below and would like to sort according to the image, however the numbers.
WITH cteNiveis(IdConta, NivelRec, NomeTab, Caminho, Nivel, Tipo, Status, Nome) AS
(
SELECT CO.Id, 1 , CAST(CO.Nome AS VARCHAR(MAX)) AS NomeTab, CAST(CO.Nome AS VARCHAR(MAX)),
CO.Nivel, TC.Nome AS Tipo, CO.Status, CO.Nome AS apenasNome
FROM Conta CO INNER JOIN TipoConta TC ON CO.IdTipoConta = TC.Id
WHERE IdContaPai = 21720
AND IdCliente = 1125
UNION ALL
SELECT C.ID, NivelRec + 1,
CAST(REPLICATE('----', NivelRec) + C.NOME AS VARCHAR(MAX)) AS NomeTab,
CAMINHO + ' \ ' + C.NOME,
C.Nivel, TC.Nome AS Tipo,
C.Status, C.Nome AS apenasNome
FROM CONTA C
INNER JOIN cteNiveis CTE ON C.IdContaPai = IdConta
INNER JOIN TipoConta TC ON C.IdTipoConta = TC.Id
)
SELECT IdConta, (CAST(Nivel as varchar(max)) + ' -' + NomeTab) AS Nivel, Caminho, Tipo, Status, Nome
FROM cteNiveis
ORDER BY Caminho, Nome
OPTION (MAXRECURSION 5)
The return is this, I hope you’ve managed to understand.
Thank you in advance to those who can help.
Note that the "Path" field of the table is like this:
Property tax "A, B or C" Lot "1, 10, 11, 12, 13, .... 2, 3, 4..."
I would like the letters "QUADRA" and the numbers of "LOTE" to be in the correct order (sequential)..
NÍVEL CAMIHO
1 - IPTU IPTU
2 -- Quadra A IPTU \ Quadra A
3 --- Lote 1 IPTU \ Quadra A \ Lote 1
3 --- Lote "2" IPTU \ Quadra A \ Lote "2"
3 --- Lote "3" IPTU \ Quadra A \ Lote "3"
3 --- Lote "4" IPTU \ Quadra A \ Lote "4"
And so on and so forth....
It’s not clear in your question what you really need to order
– Diego Marques