Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
row number in sql server 2000
row number in sql server 2000
Rate Topic
Display Mode
Topic Options
Author
Message
amol_j_kothawade
amol_j_kothawade
Posted Tuesday, January 08, 2008 11:02 PM
Forum Newbie
Group: General Forum Members
Last Login: Friday, February 08, 2008 3:06 AM
Points: 1,
Visits: 7
hi friends
i am using following row number function in my sql server 2005 :
select appno,row_number() over(partition by appno order by appno) from tab
which is giving following result :
100 1
100 2
200 1
200 2
200 3
300 1
300 2
300 3
but now i want the same result in sql server 2000
but this row number function not supported in sql 2000
so plz give me any alternate solution for this....
Post #440426
Madhivanan-208264
Madhivanan-208264
Posted Tuesday, January 08, 2008 11:29 PM
Old Hand
Group: General Forum Members
Last Login: Wednesday, September 12, 2012 5:17 AM
Points: 329,
Visits: 461
amol_j_kothawade (1/8/2008)
hi friends
i am using following row number function in my sql server 2005 :
select appno,row_number() over(partition by appno order by appno) from tab
which is giving following result :
100 1
100 2
200 1
200 2
200 3
300 1
300 2
300 3
but now i want the same result in sql server 2000
but this row number function not supported in sql 2000
so plz give me any alternate solution for this....
declare @t table(appno int, i int identity(1,1))
insert into @t
select 100 union all select 100 union all select 200 union all select 200
union all select 200 union all select 300 union all select 300 union all select 300
--method 1
select t1.appno,
(select count(*) from @t where appno=t1.appno and i<=t1.i)
from @t t1
--method 2
select t1.appno,t1.i-t2.i+1 from @t t1 inner join
(
select appno,min(i) as i from @t
group by appno
) as t2
on t1.appno=t2.appno
But if you want to show the data in front end application, start a counter, increment for each appno, reset to 1 when appno changes
If you use Crystal reports, Group the report by appno,make use of running total feature with count and reset to each appno
Madhivanan
Failing to plan is Planning to fail
Post #440432
forrajsingh
forrajsingh
Posted Friday, May 16, 2008 6:46 AM
Forum Newbie
Group: General Forum Members
Last Login: Saturday, October 20, 2012 11:46 AM
Points: 1,
Visits: 16
select *, ( select count(*)
from addOrder counter
where counter.value <= addOrder.value) as rowNumber
from addOrder
--grouped
select *, ( select count(*)
from addOrder counter
where counter.groupNumber = addOrder.groupNumber
and counter.value <= addOrder.value) as rowNumber
from addOrder
Post #501995
Mahesh Bote
Mahesh Bote
Posted Friday, May 16, 2008 6:57 AM
Ten Centuries
Group: General Forum Members
Last Login: Thursday, February 21, 2013 6:22 AM
Points: 1,074,
Visits: 1,205
...row number function not supported in sql 2000
Row_Number() is one of the new feature introduced in SQL Server 2005.
Mahesh
MH-09-AM-8694
Post #502006
arnoldsosa
arnoldsosa
Posted Tuesday, December 23, 2008 1:36 PM
Forum Newbie
Group: General Forum Members
Last Login: Friday, December 26, 2008 2:51 PM
Points: 1,
Visits: 3
Editor's note: Post edited to remove insults.
Post #624993
Steve Jones - SSC Editor
Steve Jones - SSC Editor
Posted Tuesday, December 23, 2008 1:40 PM
SSC-Dedicated
Group: Administrators
Last Login: Yesterday @ 1:47 PM
Points: 31,406,
Visits: 13,722
Please do not post insults or personal attacks in these forums.
Follow me on Twitter:
@way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
Post #625001
Ayan Bose
Ayan Bose
Posted Friday, June 04, 2010 6:49 AM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, June 30, 2011 11:27 PM
Points: 1,
Visits: 12
create table t
(
id int identity (1,1),
i int,
a varchar(10)
)
Select id,i, a, Row_Order=( select count(T1.i) + 1
from t T1
where T1.id < T.id and t1.a = t.a
)
from t T
Post #932784
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.