[URGENT] SQL - Update statement with two if condition | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

[URGENT] SQL - Update statement with two if condition

Hi. How do i update a column in table, that if it met a select statement, then it will updated to '1'. Else, it will updated to '0'. I tried this: If exist(select statement) Begin Execute(update statement to '1') End Else Begin Execute(update statement to '0') End But this query will only update to '1', and ignore the update statement to '0. Any idea?

10th Jan 2023, 2:54 AM
Azfar Hafiz Ahmad
Azfar Hafiz Ahmad - avatar
2 Respostas
+ 3
UPDATE tablename SET columnname = CASE WHEN (select statement) THEN 1 ELSE 0 END
10th Jan 2023, 3:16 AM
CalviÕ²
CalviÕ² - avatar
+ 1
CalviÕ² it's working. Thanks a lot!!
10th Jan 2023, 3:23 AM
Azfar Hafiz Ahmad
Azfar Hafiz Ahmad - avatar