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
 SQL Server Administration (2000)
 stored procedure for Roll No

Author  Topic 

Keshaba
Yak Posting Veteran

52 Posts

Posted - 2009-03-31 : 10:23:52
Hi
I want to write a query which automatically arrange the
Roll No of students in a class on the basis of there Names.
I have written a stored procedure for that but not getting the proper results.

My stored Procedure is like this

Create Procedure RollNopro
As
Declare @MM Table
(
mo int,
stname nvarchar(100),
stID int,
Rollno int
Class nvarchar(50),
Section nvarchar(2),
Session int)
insert @MM
select mo,stName,stID,RollNo,Class,Section,Session from Studentmaster as y
update t
set t.Rollno = (select Count(*) from @MM as x where x.class = t.class And x.stname<=t.stname And x.section = t.Section And x.Session = t.session) from @MM as t where t.class = '1' And t.section = ='B'
And t.Session = 2008
select * from @MM where class = '1' And Section = 'B' And Session = 2008 order by stName Asc
Return


I am getting the output like This

mo stname stID RollNo Class Section Session
92 John 6 1 1 B 2008
89 Nawajis 3 2 1 B 2008
88 Raktim 2 3 1 B 2008
87 Samim 1 4 1 B 2008
90 Tinkoo 4 6 1 B 2008
145 Tinkoo 7 6 1 B 2008
91 Udzal 5 7 1 B 2008

The problem is Roll No 6 is getting repeated

I want the output like this

mo stname stID RollNo Class Section Session
92 John 6 1 1 B 2008
89 Nawajis 3 2 1 B 2008
88 Raktim 2 3 1 B 2008
87 Samim 1 4 1 B 2008
90 Tinkoo 4 5 1 B 2008
145 Tinkoo 7 6 1 B 2008
91 Udzal 5 7 1 B 2008

Can anybody Help





Keshab
   

- Advertisement -