Row_number() Function with no specific order

Published 29 November 08 08:42 AM | Madhivanan 
 

Row_number() function is used to generate row number to rows based on the column which is ordered

What if you want to generate row number without ordering any column

Here is the method (Consider Suppliers table from northwind database)

1 Assign dummy column with literal 0 and order it by that column

select row_number() over(order by order_col),companyname,address from
(
        select companyname,address,0 as order_col from northwind..Suppliers
) as t

2 Assign dummy column with literal 0 directly on the Order by clause

select row_number() over(order by (select 0)),companyname,address from northwind..Suppliers

Also refer Multipurpose Row_Number() Function

Filed under: , ,

Comments

# SQL Server Transact-SQL (SSQA.net) : Row_number() Function with no specific order said on November 29, 2008 3:54 AM:

PingBack from http://sqlserver-qa.net/blogs/t-sql/archive/2008/11/29/5109.aspx

# Other SQL Server Blogs around the Web said on November 29, 2008 3:57 AM:

Row_number() function is used to generate row number to rows based on the column which is ordered What

Anonymous comments are disabled

Search

Go

This Blog

«November 2008»
SMTWTFS
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

Syndication