![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I would like to write a before update trigger that will check the value of a column and if the value is satisfied, I would like to stop the execution flow of the command without error. Is it possible? if so, how can Ido that? Thanks, |
#3
| |||
| |||
|
|
Think the other way round: if values IS NOT satisfied then do something else don't bother. Use old_ and new_ row variable to get values for columns. CREATE TRIGGER "Xxx" BEFORE UPDATE ORDER 1 ON "TableName" REFERENCING OLD AS old_row NEW AS new_row FOR EACH ROW /* WHEN( search_condition ) */ BEGIN if old_row.col_Val <> 'whatever' then // do something here end if; END; Clive "a.sahan" wrote in message news:4b5ed07f.3882.1681692777 (AT) sybase (DOT) com... Hi, I would like to write a before update trigger that will check the value of a column and if the value is satisfied, I would like to stop the execution flow of the command without error. Is it possible? if so, how can Ido that? Thanks, |
#4
| |||
| |||
|
|
Thank you for your reply. However, it can be misunderstood. My goal is to stop execution flow, not only trigger itself. For example, I would like to update a record in a table but if one of the columns is equal to zero, I would like to cancel update command. I can't check this before command execution. The only way is to detect it in trigger or another way. Think the other way round: if values IS NOT satisfied then do something else don't bother. Use old_ and new_ row variable to get values for columns. CREATE TRIGGER "Xxx" BEFORE UPDATE ORDER 1 ON "TableName" REFERENCING OLD AS old_row NEW AS new_row FOR EACH ROW /* WHEN( search_condition ) */ BEGIN if old_row.col_Val<> 'whatever' then // do something here end if; END; Clive "a.sahan" wrote in message news:4b5ed07f.3882.1681692777 (AT) sybase (DOT) com... Hi, I would like to write a before update trigger that will check the value of a column and if the value is satisfied, I would like to stop the execution flow of the command without error. Is it possible? if so, how can Ido that? Thanks, |
#5
| |||
| |||
|
|
If I understand your request correctly, ROLLBACK TRIGGER might be your friend, i.e. smething like (untested) CREATE TRIGGER "Xxx" BEFORE UPDATE ORDER 1 ON "TableName" REFERENCING NEW AS new_row FOR EACH ROW BEGIN if new_row.col_Val = 0 message '0 value detected: Revoke action' to log; rollback trigger; end if; END; This will undo the update itself. Note: This might work not well if used within nested triggers - cf. the docs (and the [ WITH raiserror-statement ] option). HTH Volker Am 27.01.2010 09:18, schrieb a.sahan: Thank you for your reply. However, it can be misunderstood. My goal is to stop execution flow, not only trigger itself. For example, I would like to update a record in a table but if one of the columns is equal to zero, I would like to cancel update command. I can't check this before command execution. The only way is to detect it in trigger or another way. >> Think the other way round: if values IS NOT satisfied then >> do something else don't bother. Use old_ and new_ row variable to get values for columns. CREATE TRIGGER "Xxx" BEFORE UPDATE ORDER 1 ON "TableName" REFERENCING OLD AS old_row NEW AS new_row FOR EACH ROW /* WHEN( search_condition ) */ BEGIN if old_row.col_Val<> 'whatever' then // do something here end if; END; Clive "a.sahan" wrote in message news:4b5ed07f.3882.1681692777 (AT) sybase (DOT) com... Hi, I would like to write a before update trigger that will >>> check the value of a column and if the value is satisfied, I would like to stop the execution flow of the command without error. Is it possible? if so, how can Ido that? Thanks, |
![]() |
| Thread Tools | |
| Display Modes | |
| |