Wrong order in Table valued Function(keep “order” of a recursive CTE)

后端 未结 3 1570
鱼传尺愫
鱼传尺愫 2021-01-21 07:39

a few minutes ago i asked here how to get parent records with a recursive CTE. This works now, but I get the wrong order(backwards, ordered by the PK idData) when i create a Tab

3条回答
  •  没有蜡笔的小新
    2021-01-21 08:04

    I think the impression that the CTE is creating an ordering is wrong. It's a coincidence that the rows are coming out in order (possibly due to how they were originally inserted into tabData). Regardless, the TVF is returning a table so you have to explicitly add an ORDER BY to the SELECT you're using to call it if you want to guarantee ordering:

    select * from dbo._previousClaimsByFiData(16177344) order by idData
    

提交回复
热议问题