I have the following query below and would like to sort by image, but the number.
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 have managed to understand.
Thanksinadvancetoanyonewhocanhelp.
Notethatthe"Path" field of the table looks like this:
1, 10, 11, 12, 13, .... 2, 3, 4 ... "I would like the letters "QUADRA" and the "LOT" numbers to be in the correct (sequential) order ..
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 ....