在Sybase中使用条件更新语法

时间:2017-09-21 12:44:40

标签: sybase

我需要更新具有某些条件的表,但我不知道如何为Sybase编写正确的语法。基本上只有当country为NULL并且street1,street2或street3>时才会运行更新。 40.

 UPDATE myTable
     SET status = 'X',
       reason = 'Address is too long'     

       when IsNull(Country,' ') = ' ' and Street1 > 40 OR Street2 > 40
       OR Street3 > 40

 WHERE CatName = 'BB'
 AND userid = 258
 AND status = 'A'

1 个答案:

答案 0 :(得分:1)

when逻辑移到where子句中,例如:

UPDATE myTable
    SET status = 'X',
        reason = 'Address is too long'     
WHERE CatName = 'BB'
AND   userid  = 258
AND   status  = 'A'
AND   Country is NULL
AND   (char_length(Street1) > 40 OR 
       char_length(Street2) > 40 OR 
       char_length(Street3) > 40)