It can't be done using straight forward SELECT and INSERTS. You will have to write a procedure with a cursor to go through each row of table A ordering them by code1, code2 and block, then insert multiple rows into table B.