Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

Get Dept Level of Hierarchy of Given ItemCode.

Hi,

ItemCode   ItemName   ItemGroup
SFD             Softdrink    
CCL            Coca Cola    SFD            
FNT             Fanta           SFD            
SPR             Sprite          SFD      
SPRZ             Sprite   Zero       SPR                    
ACL             Alcohol
TQL             Tequila        ACL
VDK             Vodka         ACL

I want to know a depth level for given ItemCode?  Given SPRZ get 3.

How could I do it?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of emi_sastra
emi_sastra

ASKER

Hi AngelIII,

I am not familiar with SP, would you please add sample data to it and show result at the SP?

Thank you.
Hi Sharat_123,

It works.

Thank you very much for your help.
once you created my function, you use it like this with your actual table
select t.*, dbo.GetDepth(t.ItemCode) depth
  from yourtable t

Open in new window

Hi AngelIII,

Ok.

Thank you very much for your help.