question

shallin avatar image
shallin asked

find the highest of the records

At the first there is a jsp page where the registration is done.In the registration all the details such as project title and mark secured is obtained.After that tha control is transfered to servlet page.There is a database which keeps records of all the enteries of the user.On the other part what i require is that if people enter the same title then calculation must be done and only the one with the highest mark gets the title and only his details are entered in the other database where as the others have to register again. Another option like only few say 10 people are allowed to register for a topic

sql-server-2008
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

what do you mean by "the one with the highest mark gets the title". What Title ? Can you show us your table layout, sample data and the required result ?
0 Likes 0 ·

1 Answer

·
rsheik avatar image
rsheik answered
Assume Following Table Name : Project_Table Column Names : Project_Title, Project_Marks , student_RollNo create proc Insert_Into_Project_Table_sp as begin declare @title_name varchar(max) -- topic name that u enters in GUI (html or whatever) declare @title_marks int -- marks declare @no_of_students int --- no of students per one topic declare @prepareQuery varchar(max) set @prepareQuery = 'select @no_of_students = count(student_RollNo) from Project_Table where Project_Title = '+@title_name --- selecting student count for entered topic --- print @prepareQuery --- try to print to know what is happening !!!! execute(@prepareQuery) if(@no_of_students == 0) { ---Directly insert into table } else if (@no_of_students > 10) { declare @marks_greater int select @marks_greater = count(student_RollNo) from Project_Table where Project_Marks < @title_marks if(@marks_greater >=1 ) ------------ deleting records where marks are less than entered marks for a topic set @prepareQuery ='delete from Project_Table where where Project_Title = ' + @title_name + 'and Project_Marks < ' + cast(@title_marks as varchar) --- print @prepareQuery --- try to print to know what is happening !!!! execute(@prepareQuery) insert into Project_Table ------------ Insert according to ur table-- Do u remember what u said???On the other part what i require is that if people enter the same title then calculation must be done and only the one with the highest mark gets the title and only his details are entered in the other database where as the others have to register again. else if(@marks_greater == 0 ) { print 'Insertion Cannot be Possible!! Try with other Title' } } end HOPE U GOT IT!!!!!!!!!!
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.