select reverse(left(reverse(left(d.Namespace,patindex('%.xml%',d.Namespace)-1)) ,charindex('/',reverse(left(d.Namespace,patindex('%.xml%',d.Namespace)-1)))-1)) as BaseDescriptor ,d.Namespace,d.CodeValue,d.Description,d.ShortDescription,d.DescriptorId from edfi.Descriptor d order by 1,d.DescriptorId