another option is to loop the worktype table first by the index you want and then create a nested loop with the orderdtl based on the worktype link