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

salilsingh-9961 346 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
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,871 questions
{count} votes

1 answer

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

    Check a conceptual sample code:

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