I need to set up a recursive query to solve a simple problem, but I'm having a bit of trouble.
I have a table named TABELA1
with the following fields (ID, IDPAI, NAME)
I'll put some examples of records here and what I need.
Records in the original table:
HowImanagedtogetthemthroughmyquery:
USETESTEGOWITHNiveisAS(--MembroâncoraSELECTId,IdPai,Nome,0ASNivel--nível0FROMTABELA1WHEREIdPaiISNULLUNIONALL--FilhosSELECTT1.Id,T1.IdPai,T1.Nome,Nivel+1FROMTABELA1T1INNERJOINNiveisONT1.IdPai=Niveis.Id)SELECTId,IdPai,REPLICATE('',Nivel)+NomeASNomeFROMNiveisORDERBYId,IdPai
How do I need:
Resultofthegypsy'squery,comingclosetothesolution!