Update value of other column on update of this column

Dmitriy Sosnovich

i have question, how to do something like a trigger in Intersystems Cache. Situation: for example i have table X with properties(columns) valueA,valueB i Want to update valueB when valueA changed by UPDATE. I have define global variable ^VALUEBGENER and use to increment it $SEQ function, My Idea was:

Class User.X Extends %Persistent [ ClassType = persistent, DdlAllowed, Final, Owner = {_SYSTEM}, ProcedureBlock, SqlRowIdPrivate, SqlTableName = X]
{
    Property VALUEA As %Library.String(MAXLEN = 8) [ Required,SqlColumnumber = 1];
    Property VALUEB As %Library.Integer(MAXVAL = 2147483647, MINVAL = -2147483648) [ Required,SqlColumnNumber = 1,SqlComputed,SqlColumnumber = 2, SqlComputeCode = {SET {valueB}=$SEQ(^VALUEBGENER)}, SqlComputeOnChange = %%UPDATE];
}

but it's doesnt work, when i change valuea but it works when i change valueb so, any idea? P.S. Sorry for bad english

Dmitriy Sosnovich

Can do it by adding a trigger, and SqlCompute


    Class User.X Extends %Persistent [ ClassType = persistent, DdlAllowed, Final, Owner = {_SYSTEM}, ProcedureBlock, SqlRowIdPrivate, SqlTableName = X]
    {
        Property VALUEA As %Library.String(MAXLEN = 8) [ Required, SqlComputed,SqlColumnumber = 1];
        Property VALUEB As %Library.Integer(MAXVAL = 2147483647, MINVAL = -2147483648) [ Required,InitialExpression=0,SqlColumnNumber = 2, SqlComputeCode = {SET {*}=$SEQ(^VALUEB)}, SqlComputeOnChange = %%UPDATE ];
        Trigger[Event=Update]{
           NEW valuebx
           new rowid
           set rowid={ID}
           SET valuebx= 0
           // {fieldname*C} evaluates to 1 if the field has been changed and 0 
           if({VALUEA*C}=1){
             // we trigger sql computeCode and inc of global variable by update
             //and it doesnt matter what is here in :valuebx
               &sql(update x set valueb=:valuebx WHERE ROWID=:rowid)
           }
        }
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Update a column based on the value of other column

From Dev

update column with other column

From Dev

Update a row if a column value is not the same on other table

From Dev

update column with other repeat column

From Dev

Using CASE to update column value depending on other column values

From Dev

Update column value that has one or more same values of other column

From Dev

Update value in column based on other column values in Spark

From Dev

Update column only if value doesnt exist in other column

From Dev

Update column to a value in joined column

From Dev

Column value incremental update

From Dev

Update a column with a calculated value

From Dev

update DataGridView column value

From Dev

Apache Cassandra: Update value with value of other column in same table

From Dev

Update column depending on other column by calculation

From Dev

Update a column based on other column with postgresql

From Dev

Update Table column with values for other column

From Dev

Update a Value in One Column Based on Criteria in Other Columns

From Dev

R - Update a Value in One Column Based on Criteria in Other Tables

From Dev

rails mass update column by inserting value calculated from other columns

From Dev

Postgresql Trigger based on value of one column to change or update value of other column in each row.

From Dev

update value in column and have a trigger update another column depending on the value

From Dev

How to update column value in laravel

From Dev

Update column, replace part of value

From Dev

delete or update depending column value

From Dev

oracle: update a column with not null value

From Dev

How to update column value in laravel

From Dev

Update a value in a column in Parse class

From Dev

update a certain column with a set value

From Dev

Update column value with diiferent condition

Related Related

  1. 1

    Update a column based on the value of other column

  2. 2

    update column with other column

  3. 3

    Update a row if a column value is not the same on other table

  4. 4

    update column with other repeat column

  5. 5

    Using CASE to update column value depending on other column values

  6. 6

    Update column value that has one or more same values of other column

  7. 7

    Update value in column based on other column values in Spark

  8. 8

    Update column only if value doesnt exist in other column

  9. 9

    Update column to a value in joined column

  10. 10

    Column value incremental update

  11. 11

    Update a column with a calculated value

  12. 12

    update DataGridView column value

  13. 13

    Apache Cassandra: Update value with value of other column in same table

  14. 14

    Update column depending on other column by calculation

  15. 15

    Update a column based on other column with postgresql

  16. 16

    Update Table column with values for other column

  17. 17

    Update a Value in One Column Based on Criteria in Other Columns

  18. 18

    R - Update a Value in One Column Based on Criteria in Other Tables

  19. 19

    rails mass update column by inserting value calculated from other columns

  20. 20

    Postgresql Trigger based on value of one column to change or update value of other column in each row.

  21. 21

    update value in column and have a trigger update another column depending on the value

  22. 22

    How to update column value in laravel

  23. 23

    Update column, replace part of value

  24. 24

    delete or update depending column value

  25. 25

    oracle: update a column with not null value

  26. 26

    How to update column value in laravel

  27. 27

    Update a value in a column in Parse class

  28. 28

    update a certain column with a set value

  29. 29

    Update column value with diiferent condition

HotTag

Archive