Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 RANK functions

Author  Topic 

Gigabyte
Starting Member

30 Posts

Posted - 2012-06-26 : 14:13:21
Is there any way I can create row numbers with out using order by .

I want to generate row number with out any criteria.

My table has only one row.

GIGABYTE+

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-06-26 : 14:20:08
Not that I know of. You could ORDER BY NEWID() if you wanted to assign a random numbers. Not sure what you are trying to achomplish though.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-26 : 14:24:37
For only one row, just do
SELECT 1

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-26 : 14:25:16
select top 10 row_number() over (order by (select null) )

If there's more than one row
Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-06-26 : 14:27:04
quote:
Is there any way I can create row numbers with out using order by
No, the ROW_NUMBER() function requires an ORDER BY.
quote:
I want to generate row number with out any criteria
Not sure what you mean by "criteria". If you just want row number then ORDER BY any column, or an expression like Lamprey suggested.
quote:
My table has only one row.
Ummmm, if that's the case what do the earlier statements matter? You're going to get 1 as your row number anyway.
Go to Top of Page

Gigabyte
Starting Member

30 Posts

Posted - 2012-06-26 : 14:30:38
I am sorry guys ...My table has single column but has 7 crore rows.Column type is varchar. As that column has random data I cannot give row # after sorting. I want to gve row # as they are in table and then do data manipulation.

GIGABYTE+
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2012-06-26 : 14:41:44
If you need to track the order that the rows were inserted to the table then you'll need an identity column on the table or a timestamp of some sort. Of course if multiple rows are added in a single statement then the order of those will be randomly assigned. If you have no data in the table that can differentiate the order they were inserted then there is no way to present it in the order it was inserted.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -