Reputation: 25
Hi guys, I'm quite new to SQL and I have the following question.
I have one table with two columns named student_Type
and Fees
. I need to update the Fees
column with values 5000 and 10000 where student_Type is = HomeStudent and Student_Type is = Overseas. I tried the following
UPDATE Student_Types
SET Fees= 5000,Fees=10000
WHERE Student_Type = 'HomeStudent' and 'Oversea';
I get duplication error because I have set same column twice. How can I get around this
Upvotes: 2
Views: 386
Reputation: 36431
I guess there is no real need to do it in ONE query, so why bother with IIF
?
UPDATE Student_Types
SET Fees = 5000
WHERE Student_Type = 'HomeStudent';
UPDATE Student_Types
SET Fees = 10000
WHERE Student_Type = 'Oversea';
Upvotes: 0
Reputation: 453287
One way
UPDATE Student_Types
SET Fees= IIF(Student_Type = 'HomeStudent', 5000, 10000)
WHERE Student_Type IN ('HomeStudent','Oversea');
Upvotes: 3