Unable to sort during creation of a recursive CTE IN SQL Server

salilsingh-9961 351 Reputation points
2023-04-09T17:57:33.0933333+00:00

Hi Team, In SQL Server stored procedure. I am working on creating a recursive CTE which will show the output of hierarchical data. One parent is having multiple child's, i need to sort all child's of a parent, a sequence number field is given for same. Can you please provide a sample code for same. Thanks, Salil

Azure SQL Database
SQL Server | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.8K Reputation points
    2023-04-09T18:00:43.0133333+00:00

    Check a conceptual sample code:

    . . .
    select *
    from CTE
    order by parent_id, sequence_number
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.