You can use RANK or DENSE_RANK function - probably in your case you need DENSE_RANK.SELECT *, DENSE_RANK() OVER(PARTITION BY ORDER ORDER BY [Date]) AS ReferenceFROM YourTable
If you already have a column in your table named Reference that is null now and want to update that column, you can do it like this:;with cte as( SELECT *, DENSE_RANK() OVER(PARTITION BY ORDER ORDER BY [Date]) AS NewReference FROM YourTable)UPDATE cte SET Reference = NewReference;