Answer: We need to use Row_Number() function to obtain the result. Row_Number() gives the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition. The query is
SELECT ROW_NUMBER() OVER (ORDER BY StuID ASC) AS 'SlNo' ,* from StudentMaster
I used order by with StudentID. So student id gets ordered in ascending at first and then RowNumber() function will be implemented on the result set.
The output will be
SlNo StuID SName Marks
1 S001 Naga 98
2 S102 Sundar 92
3 S158 John 85
4 S203 Ganesh 95
5 S211 Kumar 90
Asked In: GAVS Technology |
Alert Moderator