Harish Raj
Harish Raj

Reputation: 1575

Multiple Row Update by conditioning the a single column's different values

Apologies to say that I'm a newbie on the SQL side. So Let me put the scenario below for a student table.

> Roll_Number   Student_Name    isActive     Relieved_Date 
> ---------------------------------------------------------- 
> 101            John             True         NULL 
> 102            Bob              False        2015-01-20 00:00:00.000 
> 103            Joe              True         NULL 
> 104            Mike             True         NULL
> 105            Steve            False        2014-04-12 00:00:00.000
> 106            Lia              True         NULL 
> 107            Maya             True         NULL 
> 108            Gordon           True         NULL

Now I want to update the isActive column to False with the Relieved_Date = 2015-01-20 for the Roll_Number - 101, 104, 107, 108

Much appreciate if you could help me on it.

Upvotes: 0

Views: 40

Answers (3)

user3583912
user3583912

Reputation: 1322

this helps...

update YourTable
set isActive = 'False', Relieved_Date = '2015-01-20 00:00:00.000'
where Roll_Number in (101,104,107,108)

Upvotes: 1

SQLChao
SQLChao

Reputation: 7847

UPDATE Student
SET Relieved_Date = '2015-01-20', 
    isActive = 'False'
WHERE Roll_Number IN (101, 104, 107, 108)

Upvotes: 1

Rahul
Rahul

Reputation: 77926

Use a UPDATE statement like

update student
set isActive = false
where Roll_Number in (101, 104, 107, 108)
and Relieved_Date = '2015-01-20 00:00:00.000';

well may be wrong interpretation but did you said you want to set Relieved_Date = 2015-01-20 if yes, then include that to SET statement as well

update student
set isActive = false, Relieved_Date = '2015-01-20'
where Roll_Number in (101, 104, 107, 108);

Upvotes: 1

Related Questions