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
 General SQL Server Forums
 New to SQL Server Programming
 Auto Number

Author  Topic 

Sep410
Posting Yak Master

117 Posts

Posted - 2008-05-28 : 11:21:34
Hi,
I am working in SQL 2005.I need to have auto number in my query.

How should I do it?

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-28 : 11:23:45
Make use of ROW_Number() function.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-28 : 11:27:00
Refer this article to know more about ROW_NUMBER() -

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx
Go to Top of Page

Sep410
Posting Yak Master

117 Posts

Posted - 2008-05-28 : 11:35:14
Thanks for your reply. Is there any way I escape "order by" part of this function?

I am not allowed to sort the data.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-28 : 12:11:04
quote:
Originally posted by Sep410

Thanks for your reply. Is there any way I escape "order by" part of this function?

I am not allowed to sort the data.



Nope.ORDER BY is mandatory for ROW_NUMBER. The row number is actually generated in order defined by ORDER BY. Without an order on what basis do you provide row number?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-05-28 : 12:21:42
quote:

I am not allowed to sort the data.



Sounds like you should take a step back and explain your environment and exactly what you are trying to do.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -