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)
 RowNum Function in SQL 2000

Author  Topic 

cybershivanka
Starting Member

3 Posts

Posted - 2008-07-30 : 03:47:38
Is there a Function to get records in a table that between specific records Ex; 1 to 10.

I have heard a function "RowNum" Or "Row_Num" if any one know how to use this function please post a reply with sample codes ????

shivanka

pootle_flump

1064 Posts

Posted - 2008-07-30 : 04:20:29
Do you mean get row numbers for your result set? So if there are 10 rows returned, one will be numbered 1, one 2, one 3, .... up to 10?

If so then not directly in SQL 2000. ROW_NUMBER() is an Analytic Function in SQL Server 2005 that can do this efficiently and easily. It is more tricky in 2000.

This document covers the analytic functions but also covers the pre-2005 alternatives (cursors or corrolated sub selects):
http://www.insidetsql.com/OVER_Clause_and_Ordered_Calculations.doc
Go to Top of Page

cybershivanka
Starting Member

3 Posts

Posted - 2008-07-30 : 07:05:12
quote:
Originally posted by pootle_flump

Do you mean get row numbers for your result set? So if there are 10 rows returned, one will be numbered 1, one 2, one 3, .... up to 10?

If so then not directly in SQL 2000. ROW_NUMBER() is an Analytic Function in SQL Server 2005 that can do this efficiently and easily. It is more tricky in 2000.

This document covers the analytic functions but also covers the pre-2005 alternatives (cursors or corrolated sub selects):
http://www.insidetsql.com/OVER_Clause_and_Ordered_Calculations.doc




I need to know how to do it in SQL 2000 if there is away to do this !! Thank you for your reply ! If you have any solution ? Please let me know ?

shivanka
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2008-07-30 : 07:20:47
Did you read the article? Examples of both techniques I mentioned are in there. You'll find more examples via google also.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-30 : 07:23:06
quote:
Originally posted by cybershivanka

Is there a Function to get records in a table that between specific records Ex; 1 to 10.

I have heard a function "RowNum" Or "Row_Num" if any one know how to use this function please post a reply with sample codes ????

shivanka


Where do you want to show data?
If you use front end application, do numbering there

Madhivanan

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

cybershivanka
Starting Member

3 Posts

Posted - 2008-07-30 : 07:39:48
quote:
Originally posted by pootle_flump

Did you read the article? Examples of both techniques I mentioned are in there. You'll find more examples via google also.



I read part of the article which includes the RowNum() Function used with OVER Aggregates, But i didnt see where it incudes the way to do it in sql 2000! may be i didnt read that far !

shivanka
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2008-07-30 : 08:28:55
Page four onwards - Cumulative Aggregations. Except instead of SUM(Q2.qty) you will use COUNT(*).

As Maddhi says (and I forgot) this is best accomplished in your front end reporting app where possible.
Go to Top of Page
   

- Advertisement -