I would like to generate a line number for each line in the results of a sql query. How is it possible to do that?
Example: In the request
select di
You can use the ROW_NUMBER function for this. Check the syntax for this here http://msdn.microsoft.com/en-us/library/ms186734.aspx
SELECT FirstName, LastName, ROW_NUMBER() OVER(ORDER BY FirstName) AS 'Row#'
FROM Sales.vSalesPerson;
For your query,
SELECT client_name, ROW_NUMBER() Over (Order By client_name) AS row_number
FROM (select distinct client_name from deliveries) SQ
will work.