Hello,
I wrote an update trigger to detect the names of the updated columns of a table using the UPDATED(columnN ame) function.
In a stored procedure I wrote code to update user information with given parameters.
My problem is, that this statement updates all the columns (strFirstName, strLastName and strEMail), but I dont want to update a column, if the old value matches the new value.
My first idea was:
Okay, the script above only updates columns with new values, if they are not like the old values.
But that's not the effect, I want, cause in the case, that the new value matches the old value, the script above will update the field with NULL value.
What I need is something like the following, but it doesn't works:
Can somebody help me to find a way?
Norman
I wrote an update trigger to detect the names of the updated columns of a table using the UPDATED(columnN ame) function.
In a stored procedure I wrote code to update user information with given parameters.
Code:
Update daUser SET strFirstName = @vstrFirstName, strLastName = @vstrLastName, strEMail = @vstrEMail WHERE uidUserGuid = @vuidUserGuid
My first idea was:
Code:
UPDATE daUser SET daUser.strFirstName = CASE WHEN daU.strFirstName <> @vstrFirstName THEN @vstrFirstName END, daUser.strLastName = CASE WHEN strLastName <> @vstrLastName THEN @vstrLastName END, strEMail = CASE WHEN strEMail = @vstrEmail THEN @vstrEMail END FROM daUser daU WHERE daU.uidUserGuid = @vuidUserGuid
But that's not the effect, I want, cause in the case, that the new value matches the old value, the script above will update the field with NULL value.
What I need is something like the following, but it doesn't works:
Code:
UPDATE daUser SET CASE WHEN daUser.strFirstName <> @vstrFirstname THEN strFirstName = @vstrFirstName END, CASE WHEN daUser.strLastName <> @vstrLastName THEN strLastName = @vstrLastName END, CASE WHEN daUser.strEMail <> @vstrEMail THEN strEMail = @vstrEMail END FROM daUser daU WHERE daU.uidUserGuid = @vuidUserGuid
Norman
Comment