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)
 Row Number Function

Author  Topic 

Jonny1409
Posting Yak Master

133 Posts

Posted - 2009-01-16 : 04:55:50
Hello,

I'm aware there is a row number function in SQL 2005 that I could use in a view and it would provide me with a column which would simply increment from 1 to x.

What would the equivalent code be in SQL 2000 ?
If it is even possible.

Thanks,

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-16 : 05:18:20
Yes, it is possible.

1) Use a correlated subquery
2) Use a temp table



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

ra.shinde
Posting Yak Master

103 Posts

Posted - 2009-01-16 : 05:23:03
quote:
Originally posted by Peso

Yes, it is possible.

1) Use a correlated subquery
2) Use a temp table



E 12°55'05.63"
N 56°04'39.26"




Temp table -- Ok
How can we use a correlated subquery


Rahul Shinde
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-16 : 06:20:35
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=6195
Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-01-16 : 07:16:51
Yes the Row Number is also generated by the method as Sodeep Sir Suggested But the Time Is Taken by the query is much more,,,,,
It fetch only 56113 records in 4:23 seconds.......
But It Is possible to use correlated queries to get the Row Number In Sql 2000


I Use same query as stated in Above Topic like this,,,,

SELECT custid,cust_firstname, fathername,
(SELECT COUNT(*) FROM test25 e2 WHERE e2.custid <= e.custid) AS rownumber
FROM test25 e
ORDER BY custid
In which Custid is indexed as unique cluster

Thanks...
Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-01-16 : 07:21:14
Also it works faster when we use this query without using the * order by * clause.......


if u use only this then ...

SELECT custid,cust_firstname, fathername,
(SELECT COUNT(*) FROM test25 e2 WHERE e2.custid <= e.custid) AS rownumber
FROM test25 e


But Still it slow...

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-01-16 : 07:23:53
quote:
Originally posted by Jonny1409

Hello,

I'm aware there is a row number function in SQL 2005 that I could use in a view and it would provide me with a column which would simply increment from 1 to x.

What would the equivalent code be in SQL 2000 ?
If it is even possible.

Thanks,


Where do you want to show data?

Madhivanan

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

- Advertisement -