Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Recursive cte (common table expression)
with pilots_cte as ( select pilots.ID, pilots.First_name, pilots.Last_name, pilots.Title, pilots.Birth_date, pilots.Pilots_ID, cast(RIGHT(REPLICATE('0',12) + CONVERT(varchar(12), pilots.id),12) as varchar(max)) Path from Pilots pilots where pilots.Pilots_ID is null union all select pilots.ID, pilots.First_name, pilots.Last_name, pilots.Title, pilots.Birth_date, pilots.Pilots_ID, pcte.Path+cast(RIGHT(REPLICATE('0',12) + CONVERT(varchar(12), pilots.id),12) as varchar(max)) Path from Pilots pilots inner join pilots_cte pcte on pcte.ID = pilots.Pilots_ID ) select * from pilots_cte order by Path
run
|
edit
|
history
|
help
0
Manish_SQL_11_dec
My data
28-02
reee
Creation tables
Libros
TABLE
Task_3_Final
Recursive CTE termination
Use the right tool to get identity values back after an insert