select *,ROW_NUMBER() OVER(PARTITION BY FItemID ORDER BY FOrderPrice) as num into #t1 from ICStockBillEntry where finterid=@interid-- select * into #t2 from #t1 where num=1