I got it to work in SQL but I figured out that it's not a SQL issue this line works:
select * Into NewTabe from( select *, row_number()over(partition by Code order by Code) As rn From database) t where rn = 1 order by Code
This issue is I am trying to run this sql statement through vb.net, and vb.net does not support row number() or partition....