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 |
Keshaba
Yak Posting Veteran
52 Posts |
Posted - 2009-03-31 : 10:23:52
|
HiI 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 thisCreate Procedure RollNoproAsDeclare @MM Table(mo int,stname nvarchar(100),stID int,Rollno intClass nvarchar(50),Section nvarchar(2),Session int)insert @MMselect mo,stName,stID,RollNo,Class,Section,Session from Studentmaster as yupdate tset 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 = 2008select * from @MM where class = '1' And Section = 'B' And Session = 2008 order by stName AscReturn I am getting the output like Thismo stname stID RollNo Class Section Session 92 John 6 1 1 B 200889 Nawajis 3 2 1 B 200888 Raktim 2 3 1 B 200887 Samim 1 4 1 B 200890 Tinkoo 4 6 1 B 2008145 Tinkoo 7 6 1 B 200891 Udzal 5 7 1 B 2008The problem is Roll No 6 is getting repeated I want the output like thismo stname stID RollNo Class Section Session 92 John 6 1 1 B 200889 Nawajis 3 2 1 B 200888 Raktim 2 3 1 B 200887 Samim 1 4 1 B 200890 Tinkoo 4 5 1 B 2008145 Tinkoo 7 6 1 B 200891 Udzal 5 7 1 B 2008 Can anybody HelpKeshab |
|
|
|
|