First add a Column 'ID' to the table Customers
ALTER TABLE Customers
ADD ID int null
GO
Now execute the following code to insert data into the ID column based on some columns.
UPDATE temp
SET ID=Rowno
FROM
(
SELECT ID, ROW_NUMBER() OVER (ORDER BY [Country] asc, [City] asc, [Address] desc) AS Rowno
FROM Customers
)temp
The query shown above inserts data into the ID column based on the Country, City and Address fields
No comments:
Post a Comment