Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


row number in sql server 2000


row number in sql server 2000

Author
Message
amol_j_kothawade
amol_j_kothawade
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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....
Madhivanan-208264
Madhivanan-208264
Old Hand
Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)

Group: General Forum Members
Points: 335 Visits: 476
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
forrajsingh
forrajsingh
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 17
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
Mahesh Bote
Mahesh Bote
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1104 Visits: 1274
...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
arnoldsosa
arnoldsosa
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 3
Editor's note: Post edited to remove insults.
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: Administrators
Points: 35984 Visits: 18728
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
My Blog: www.voiceofthedba.com
Ayan Bose
Ayan Bose
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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
                     Wink
from t T
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search