• river1 (10/30/2012)


    The code:

    update

    contribuintes

    set

    nif = c.nif

    from

    contribuintes c

    join

    inserted i

    on

    i.nif_antigo = c.nif_antigo

    where

    i.numeroposto = 'Central'

    Has a problem.

    I want that If the value from NIF is changed, then it needs to get back to the original value again.

    So, why use the inserted instead of the deleted table?

    You need to look at inserted to know if the new value of numeroposto = 'Central'. It actually doesn't matter if the new value for nif is the same or not, you want the old value either way. Keep in mind I can't actually test anything here, I am coding 100% blind because we don't have any ddl.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/