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.
Author |
Topic |
icw
Constraint Violating Yak Guru
378 Posts |
Posted - 2010-03-29 : 01:00:08
|
Hi I have a table with potentially several rows for each unique accountno (i.e. each company). I would like to add a column that is a row count for each accountno no.e.g. Table looks like thisAccountno dateabc123 01/01/98abc123 23/03/03def345 21/01/91abcdef 30/01/08def345 12/06/09ghi678 13/02/03I would like to select it and add the rowcount so it looks like thisRow Accountno date 1 abc123 01/01/98 2 abc123 23/03/03 3 abcdef 30/01/08 1 def345 21/01/91 2 def345 12/06/09 1 ghi678 13/02/03 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-29 : 01:24:33
|
[code]SELECT (SELECT COUNT(*) FROM Table WHERE Accountno=t.Accountno AND date < t.date) + 1 AS Row,Accountno,dateFROM table t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
icw
Constraint Violating Yak Guru
378 Posts |
Posted - 2010-03-29 : 01:34:48
|
That's Greatthanks a lot Visakh16 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-29 : 02:02:42
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|