SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Please HELP - adding counter
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

zoe2003
Starting Member

15 Posts

Posted - 11/07/2012 :  07:13:57  Show Profile  Reply with Quote
Hi,

I need to add a counter for each change in 2 columns like following:
this is the original table :
column1 column2
1 2
1 2
1 3
1 4
1 5
2 10
2 11
2 12
2 15
2 20

and I want a 3rd column like following:
column1 column2 counter
1 2 1
1 2 2
1 3 3
1 4 4
1 5 5
2 10 1
2 11 2
2 12 3
2 15 4
2 20 5


Thanks,
Z.

stepson
Constraint Violating Yak Guru

Romania
439 Posts

Posted - 11/07/2012 :  07:22:03  Show Profile  Reply with Quote
select *
,ROW_NUMBER () OVER ( PARTITION BY column1 order by column1 ) as column3
from A

What you mean when You say "for each change in 2 columns" ?

the exemple shown by you , only the change in column 1

Edited by - stepson on 11/07/2012 07:28:25
Go to Top of Page

zoe2003
Starting Member

15 Posts

Posted - 11/07/2012 :  07:32:00  Show Profile  Reply with Quote
Thanks a lot !
This is what I needed.
Go to Top of Page

stepson
Constraint Violating Yak Guru

Romania
439 Posts

Posted - 11/07/2012 :  07:45:38  Show Profile  Reply with Quote
w. welcome
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000