Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with.
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | niyaz4872Starting Member
 
 
                                        41 Posts | 
                                            
                                            |  Posted - 2014-10-21 : 05:34:32 
 |  
                                            | following is my table structureID             level    sys_ID  ref_ID1286403304	2	2110	2791286403118	3	2115	21101286412300	3	2116	21101286403023	4	2127	21151286411200	4	2128	21151286412101	4	2404	21161286409100	5	2405	24041286410101	5	2406	24041286411100	5	2129	2128following is sample results i wan'tID             level    sys_ID  ref_ID1286403304	2	2110	2791286403118	3	2115	21101286403023	4	2127	21151286411200	4	2128	21151286411100	5	2129	21281286412300	3	2116	21101286412101	4	2404	21161286409100	5	2405	24041286410101	5	2406	2404 |  |  
                                    | gbrittonMaster Smack Fu Yak Hacker
 
 
                                    2780 Posts | 
                                        
                                          |  Posted - 2014-10-21 : 08:45:19 
 |  
                                          | What have you tried so far? |  
                                          |  |  |  
                                    | niyaz4872Starting Member
 
 
                                    41 Posts | 
                                        
                                          |  Posted - 2014-10-21 : 14:22:53 
 |  
                                          | Hi All I was doing this regularly. But I do not know how |  
                                          |  |  |  
                                    | gbrittonMaster Smack Fu Yak Hacker
 
 
                                    2780 Posts | 
                                        
                                          |  Posted - 2014-10-21 : 14:41:35 
 |  
                                          | Well, you really should try to write the query yourself before posting here.  Your sample data seems to be the same in input and output, except for the order.  What do you actually want to achieve? |  
                                          |  |  |  
                                |  |  |  |