SQLTeam.com | Weblogs | Forums

row_number


#1

Is there a way I can use row_number() over (order by)

To get my rows to count by 2's?

So I would want

2
4
6
8
10


#2

Do you mean jultiply by 2, or are you trying to implement some logic to skip some of the rows?

2*ROW_NUMBER() OVER( ORDER BY Something)

#3

What about doing odd numbers?

1
3
5
7


#4
2*ROW_NUMBER() OVER( ORDER BY Something) - 1

You can use the result of the row_number function in expressions and calculations within the select clause just like you would use any other variable/column.