SELECT UserId,
            DisplayName,
            AgentLevel,
            AgentId,
            ParentPath,
            CreateTime,
		    Charindex('101398',ParentPath) AS inex1,
			Patindex('%101398%',ParentPath)AS index2,
			Substring(ParentPath,Charindex('101398',ParentPath),Len(ParentPath)) AS VParentPath,--匹配字符之后数据
			((Len(Substring(ParentPath,Charindex('101398',ParentPath),Len(ParentPath)))-Len(
			Replace(Substring(ParentPath,Charindex('101398',ParentPath),Len(ParentPath)),'/',''))+1
            ))HierarchyLevel
     FROM   [C_User_Register]
     WHERE  ( ParentPath LIKE'%101398%' )

SQL SERVER 分层如/101398/101480_数据

参考地址:https://blog.csdn.net/m0_37841468/article/details/127343744