I have some data which is serially order by column ID. Within the data there is a column 'Ueid' which has employee numbers. A same Ueid could be present on more than one row if an employee has more than one record. To get a data for an employee serialized by time order i use below command and it works fine
SELECT ROW_NUMBER() OVER(PARTITION BY Ueid ORDER BY ID ASC) AS RowNumber, *
FROM [dbo].[checking]
order by ID
I want to add the column 'RowNumber' to my original data. What is an efficient way to do it?
I am thinking of using below command, but i am getting errors.
1 Error says that "the multi-part identifier "newone.[ID]" and "newone.[Row]" couldn't be bound"
2 Error says that "Invalid column name RowNumber"
with newone as (SELECT ROW_NUMBER() OVER(PARTITION BY Ueid ORDER BY ID ASC) AS RowNumber, *
FROM [dbo].[checking])
update [dbo].[checking]
set Rownumber = newone.[RowNumber]
where [dbo].[checking].ID = newone.[ID]