April 28, 2018 at 1:59 am
Hi,
Please refer to the attached image for your kind perusal.
For example the product in level 1 contains multiple items as per the BOM list in further levels.
I tried to generate a hierarchy model as per the BOM list using recursive cte.
The hierarchy is displayed but the ordering is misplaced.
How to arrange the ordering?
Please advise.
Thank you.
April 28, 2018 at 4:23 am
kiran 4243 - Saturday, April 28, 2018 1:59 AMHi,
Please refer to the attached image for your kind perusal.
For example the product in level 1 contains multiple items as per the BOM list in further levels.
I tried to generate a hierarchy model as per the BOM list using recursive cte.
The hierarchy is displayed but the ordering is misplaced.
How to arrange the ordering?
Please advise.
Thank you.
April 28, 2018 at 5:43 am
Do you happen to have an id field on the level2 column. such as level2_id that you wish to order by
If you do then you can order by the parentid, level1, followed by level2
If you don't then you would need to define the "ordering" of how you want to display the level2 columns. such as by level 2 name. or a substring of level 2 Name that contains just the numerical portion, for example.
with cte(col1, col2)
as (-- Query for CTE Hierarchy here..
)
select *
from cte
order by parentid,level
,substring(Name
,4
,patindex('%[^0-9]%',substring(Name,4,datalength(Name)))-1 /*First 4 characters are "GJ-", From the 4th Character i am looking for the first non numeric character to (using patindex) to extract the numerical portion of the data*/
)
Note:The records in a table are not ordered by anything, and therefore we cannot force that order in the desired query output.
Hope this helps
April 28, 2018 at 1:53 pm
kiran 4243 - Saturday, April 28, 2018 1:59 AMHi,
Please refer to the attached image for your kind perusal.
For example the product in level 1 contains multiple items as per the BOM list in further levels.
I tried to generate a hierarchy model as per the BOM list using recursive cte.
The hierarchy is displayed but the ordering is misplaced.
How to arrange the ordering?
Please advise.
Thank you.
Please see the following article on how to control the order plus much more.
http://www.sqlservercentral.com/articles/Hierarchy/94040/
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply