Q&A for anime and manga fans
declare @t table ( orderId int, code_dest char(1) ) declare @t2 table ( ID_VOIT int, orderId int, code_dest char(1) ) insert into @t values (1, 'a') insert into @t values (2, 'b') insert into @t values (3, 'c') insert into @t values (4, 'a') insert into @t values (5, 'a') insert into @t values (6, 'b') insert into @t values (7, 'g') insert into @t2 select case code_dest when 'a' then 1 when 'b' then 2 when 'c' then 3 when 'g' then 4 else 0 end, orderId, code_dest from @t order by code_dest, orderId select * from @t2