My source is as follows
OSPID OSPNAME RELATEDOSPID
100004 LEVEL4 100003
100003 LEVEL3 100002
100002 LEVEL2 100001
100001 LEVEL1 0
100009 LEVEL4 100008
100008 LEVEL2 100007
I need the result as
L4OSPID L4OSPNAME L3RELATEDID L3OSPNAME L2RELATEDID L2OSPNAME L1RELATEDID L2OSPNAME ROOTNODE
100004 LEVEL4 100003 LEVEL3 100002 LEVEL2 100001 LEVEL1 0
100009 LEVEL4 100008 NULL NULL LEVEL2 100007 NULL NULL
If any level in between is missing should put NULL
Thanks