Search code examples
sqlsql-updatesqlanywhere

What is the best solution for this UPDATE


what is the best way for this SQL?

A)

update tableName set 
FieldA = (if FieldA = 1301 then null else FieldA endif), 
FieldB = (if FieldB = 1301 then null else FieldB endif)
where Id = 707;

or

B)

update tableName set FieldA = null where Id= 707 and FieldA = 1301;
update tableName set FieldB = null where Id= 707 and FieldB = 1301;

In Model "A" I only have one SQL that works and solves the problem, and model "B" I have two SQL's, that do the same thing as the "A" model but more readable.

What would be the most appropriate model to use?


Solution

  • I suppose that A solution is better because:

    1 less logical IO - better performance

    2 less program code, less errors

    3 ease to support and maintain

    4 this update is pretty readable