If dates are not unique just do thisDeclare @T table( customerID int,OrderID int,date_ datetime)insert into @T select '123','5465363','2012/10/01'union all select '123','5465363','2012/10/01'union all select '124','6545344','2012/10/01'union all select '124','6545348','2012/10/02'union all select '124','6545353','2012/10/04'Select identity(int,1,1)ID,* into #ROWNUMBERfrom @Tselect s1.customerID ,s1.OrderID ,s1.date_ ,row_number() over (partition by s1.CustomerID order by (select getdate())) as showOrder ,showOrder2 = ( select count(*) from #ROWNUMBER as s2 where s2.CustomerID = s1.CustomerID and ID < = s1.ID )from #ROWNUMBER as s1