How to update different values for a singal column

  • 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.

  • 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

  • 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.

  • 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

  • Try this code....

    1. UPDATE t1

    2. SET t1.colx=t2.colx

    3. FROM t1,t2

  • Try this code....

    1. UPDATE t1

    2. SET t1.colx=t2.colx

    3. FROM t1,t2

    Didnt get the point....

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

  • WHEN (marks between 60 and 79) THEN 'C'

    Just one thing. Replace 79 with 78.

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply