'How do I update "case when" kogi mosi [closed]
update [dbo].[student]
set marks = case
when marks > 60 then 'Good'
when marks >= 40 and marks <= 60 then 'Okay'
when marks < 40 then 'Fail' end
--where marks in (60, 40)
select * from student
I already have a table with some sample data. When I execute this I get: Error converting data type varchar to numeric.
Solution 1:[1]
Your marks variable is initially a number which is how you're comparing it to values such as 60 or 40.
The issue you're having is you're trying to SET marks to 'Good' or 'Okay' which is a varchar.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joe |
