There might be a better way depending on what you really need as output. But, maybe you can make use of the Dense_Rank() function:declare @T table(ID int, Permit# INT, LocationID varchar(20), WorkType varchar(20))insert @Tvalues (1, 349, '1a', 'Add room'),(2, 350, '2c', 'replace windows'),(3, 351, '1a', 'install footers'),(4, 352, '456c', 'new construction'),(5, 353, '456c', 'electric')select *, dense_rank() over (order by LocationID) as RowRankfrom @T