March 21, 2004 at 5:02 am
Hi all,
I am a newbie to SQL server and at the moment I am trying to write a trigger that fires if the value of a field is changed. The trigger works i.e. I can update the filed to a value I specify
eg UPDATE Employees SET lastname = 'papa' WHERE lastname = 'king'
What I would like to do is update the field to a value stored in another field in the database. Is this possible and how would I go about doing it.
Something like this
UPDATE Employees SET lastname = ?????? WHERE lastname = 'king'
Where the ????? would be a reference to the field that contains the value
Regards
Lee
March 21, 2004 at 5:17 am
If you want to update the lastname value to equal the value of a column that has the lastname value of king
update Employees SET lastname = newlastname where lastname = 'king' --(newlastname being the column that you want to use to populate the lastname column)
March 21, 2004 at 6:28 am
Unless that field isn't in the same table then you do something like this.
Update E
SET Lastname = T2.newlast
FROM
Employees E
INNER JOIN
table2 T2
ON
E.coltolink = T2.coltolink
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy