1 now has the following table:
CREATE TABLE [dbo]. [Themecategory] ([ID] [int] not null,[themecategoryname] [nvarchar] (+) COLLATE chinese_prc_ci_ As null,[themecategorycode] [nvarchar] (+) COLLATE chinese_prc_ci_as Null,[parentid] [ int] Null,[orderid] [int] NULL) on [Primary]goalter TABLE [dbo]. [Themecategory] ADD CONSTRAINT [pk_themecategory] PRIMARY KEY CLUSTERED ([ID]) on [Primary]go
which
ParentID
is its parent ID.
Now there is a requirement that the ID of a record be recursively returned to its ancestor records, that is, backward pushing back
2 The contents of the table are as follows
ID themecategoryname themecategorycode parentid OrderId1 1 tcfl 0 4352 2 2 0 433 3 3 0 - 1111 1 -2 546 211 sdfsd 5 342
3 ways to implement recursive traversal
withTemp_themecategory ([Id],[ParentID],[Themecategoryname]) as( Select [Id],[ParentID],[Themecategoryname] frompe_c_themecategorywhereId= @publicThemeId Union All Selecta.id, A.parentid,a.themecategoryname fromThemecategory aInner JoinTemp_themecategory onA.[ID] =Temp_themecategory.[ParentID]) Select * fromTemp_themecategoryORDER byIdASC
That's what we found.
Recursive query constructs jquery tree