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 2000 Forums
 Transact-SQL (2000)
 Running number in result

Author  Topic 

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2008-08-04 : 21:21:25
I've this in SQL Server 2000

Select AccNo,CstNme
from v_cst

Then the result as follow,
AccNo | CstNme
-----------------
002 | Gwoh Burne Loh
003 | Tesk Ji
005 | UJIK
...
...

How to adjust my query to add i more column as number so te result as follow
No. | AccNo | CstNme
-------------------------
1 | 002 | Gwoh Burne Loh
2 | 003 | Tesk Ji
3 | 005 | UJIK
4 | ...
...

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-08-04 : 22:50:08
No real good way to do that in sql 2000. Here are 3 possibilities:

1) upgrade to 2005 and use the rownumber() function
or
2) create a temp table with an identity column, use your query to insert into the temp table, then SELECT from your temp table.
or
3) use a correlated subquery:
select AccNo, CstNme, (select count(*) from v_cst where AccNo <= c.AccNo) as [No.] from v_cst c

Be One with the Optimizer
TG
Go to Top of Page

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2008-08-04 : 23:31:47
thanks a lot ... it give me a great idea.
Go to Top of Page
   

- Advertisement -