Sometimes we may not want to apply the order in our result set to add a serial number. But if we use ROW_NUMBER() , then we should have an ORDER BY . Thus, for this we can simply apply tricks to avoid ordering in the result set.
SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS ItemNo, ItemName FROM ItemMastetr
To do this, we do not need to apply order on our result set. We will simply add ItemNo to our specified result set.
source share