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 2005 Forums
 Transact-SQL (2005)
 t-sql

Author  Topic 

bondwiththebest
Starting Member

46 Posts

Posted - 2009-05-08 : 16:01:09
Hi,

I have the results of the query like this below.............The "Total" value should be like something shown below..

ID CID Total Value1

3 AA 3 820
4 AA 3 1640
5 AA 3 1221
6 AB 2 820
7 AB 2 1640


I have this results in a temp table.Here the "total" needs to increment by value 1 ,max out and reset. I want the output of the query like this. Can anyone help ,me >?

ID CID Total Value1

3 AA 1 820
4 AA 2 1640
5 AA 3 1221
6 AB 1 820
7 AB 2 1640

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-05-08 : 16:05:28
[code]
select
ID,
CID,
row_number() over (partition by CID order by ID ) as Total,
Value1
from table
[/code]


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-09 : 01:32:30
Also see what you can do with Row_number() function
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -