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 |
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 subquery2) Use a temp table E 12°55'05.63"N 56°04'39.26" |
|
|
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 subquery2) Use a temp table E 12°55'05.63"N 56°04'39.26"
Temp table -- OkHow can we use a correlated subqueryRahul Shinde |
|
|
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 |
|
|
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 2000I 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 rownumberFROM test25 eORDER BY custidIn which Custid is indexed as unique clusterThanks... |
|
|
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 rownumberFROM test25 eBut Still it slow... |
|
|
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?MadhivananFailing to plan is Planning to fail |
|
|
|
|
|
|
|