Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert row_number() to int in sql server

I have a query where i have used row_number() function. My query is like the following

SELECT ID, 
ROW_NUMBER() over(order by Position desc) Rank
FROM Tbl

Problem is Rank is producing a bigint value. But i want to convert it to an int. How can i do it?

like image 645
Yeasin Abedin Avatar asked Mar 24 '15 07:03

Yeasin Abedin


2 Answers

This isn't particularly difficult;

SELECT ID, 
CAST(ROW_NUMBER() over(order by Position desc) AS INT) Rank
FROM Tbl
like image 182
Rhys Jones Avatar answered Oct 17 '22 23:10

Rhys Jones


SELECT name, 
cast (ROW_NUMBER() over(order by object_id desc) as int) Rank
FROM sys.objects
like image 30
fly_ua Avatar answered Oct 17 '22 22:10

fly_ua