Daniel_Ranjbar
Daniel_Ranjbar

Reputation: 120

How to add Row Number Column at the beginning of my table in SQL?

select 
    CodeColumn, NameColumn, UnitCostColumn, DiscountRateColumn,
    TotalColumn, DescriptionColumn,
    row_number() over (order by CodeColumn) AS RowNumber
from 
    GoodsTable1

This is the code I use. But it adds RowNumber at the end of my table. I don't want that

Upvotes: 1

Views: 73

Answers (1)

Mureinik
Mureinik

Reputation: 311478

Just move that "column" to the beginning of the select list:

SELECT ROW_NUMBER() OVER (ORDER BY CodeColumn) AS RowNumber, -- Here!
       CodeColumn,
       NameColumn,
       UnitCostColumn,
       DiscountRateColumn,
       TotalColumn,
       DescriptionColumn
FROM   GoodsTable1

Upvotes: 1

Related Questions