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
 How can I add number(in sequential order)

Author  Topic 

arun0404
Starting Member

2 Posts

Posted - 2010-05-04 : 02:55:15
How can I add number(in sequential order) based >on the values on another column. Whenever the value >changes again, the number need to restart as '1' again.

arun

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-04 : 03:01:09
you need to provide more information for us to help you.

With just the brief description, all i can say is to check out row_number()


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-04 : 04:01:03
seems like what you need is ROW_NUMBER() function along with PARTITION BY. have a look at synatx in books online. If need more help, then post sample data along with required output

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-05-04 : 06:19:49
"seems like what you need is ROW_NUMBER() function along with PARTITION BY. ..."

There is also an example in Madhi's blog:

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

- Advertisement -