Recursive query constructs jquery tree

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.