April 29, 2010 at 11:58 pm
Hello
I have a table of student records in that table i have columns
RollNo, Name, Marks Grade.
Now i want to assign grades to students according to their marks e.g if marks in between 99-90 then grade A, 89-80 grade B, 79-70 grade C, 69-60 Grade D an so on...
for that I am using following command
update students set grade="A" where (select from students where marks in between 99 and 90)
but from that command I can assign only one grade can any one guide me how to update grades of students in singal query.
April 30, 2010 at 12:01 am
Are you trying to write multiple mark's into a single column, but not overwrite, just append next to each other?
or
Are you trying to write multiple rows for each student for different marks?
or do you want to use one query to update the column?
yes?
try:
UPDATE students
SET GRADE =
CASE
WHEN (marks > 90)
THEN marks = 'A'
WHEN (marks between 79 and 90)
THEN marks = 'B'
--etc.....
END
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle
April 30, 2010 at 12:30 am
i want to set grade A for these students who's marks in bet ween 99 to 90 its mean there may multiple rows updated at a time.
April 30, 2010 at 12:48 am
The below Query Will update all the recodes (Multiple)
UPDATE student_records
SET GRADE =
CASE
WHEN (marks > 90) THEN 'A'
WHEN (marks between 79 and 90) THEN 'B'
WHEN (marks between 60 and 79) THEN 'C'
WHEN (marks < 60) THEN 'D'
END
May 2, 2010 at 10:17 pm
May 6, 2010 at 10:44 pm
Try this code....
1. UPDATE t1
2. SET t1.colx=t2.colx
3. FROM t1,t2
Didnt get the point....
May 6, 2010 at 10:45 pm
WHEN (marks between 60 and 79) THEN 'C'
Just one thing. Replace 79 with 78.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply