简体   繁体   中英

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?

This isn't particularly difficult;

SELECT ID, 
CAST(ROW_NUMBER() over(order by Position desc) AS INT) Rank
FROM Tbl
SELECT name, 
cast (ROW_NUMBER() over(order by object_id desc) as int) Rank
FROM sys.objects

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM