How would I dynamically number rows in a query similar to this:
Select distinct name from @table where %rules
When I add ROW_NUMBER() OVER() I lose my distinct property, and it returns every element in table, with a unique row number.
Select distinct ROW_NUMBER OVER(order by name), name from @table where %rules
I don't want to create a temporary table, otherwise I would make a primary key for the temporary table and have it insert row numbers that way.
Thanks in advance!
Use like this.
select ROW_NUMBER() OVER(order by name), * from
(Select distinct name from @table where %rules) as mytable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With