Row_number() function in sql server is used to generate a serial number for a given record set. But we need to use ORDER BY clause so that the numbers are assigned to the specific order.
CREATE TABLE #TEMP (NAMES VARCHAR(100)) INSERT INTO #TEMP SELECT 'Hitesh' UNION ALL SELECT 'Abhimanyu' UNION ALL SELECT 'Priyanka' UNION ALL SELECT 'Dev' UNION ALL SELECT 'Bhawesh' SELECT NAMES,ROW_NUMBER() OVER (ORDER BY NAMES) AS SNO FROM #TEMP drop table #TEMP
Result :