I have an UPDATE statement in SQL Server that runs several UDFs encapsulating necessary business logic. So a user can opt in or opt out of communications with our company and we have a bunch of permission codes corresponding to the various communications we send people. We not only have a permission field but we have a Do Not Promote field as well. If someone has opted out of a permission then we want to move it and its associated permissions to the DNP field.
So Lets say a user has the following field values
PermissionCodes DoNotPromoteCode
A|B|C|D| Z|
Now the user opts out of A but when he opts out of A then our company wants to opt him out of codes C and G as well and add those values to the DoNotPromote field, but only add them to the DNP if they were in the Permissions field. i.e.
PermissionCodes DoNotPromoteCode
B|D| Z|A|C|
So I have this query:
UPDATE Permissions
SET PermissionCodes = dbo.RemovePermissions('A'),
DoNotPromoteCodes = dbo.AddDoNotPromote('A', PermissionCodes)
WHERE Email = 'john.doe@yahoo.com'
The UDF "dbo.RemovePermissions" will remove the Permission you pass in and all other Permissions that are related to it. The UDF "dbo.AddDoNotPromote" adds the permission to the DoNotPromote field and then searches PermissionCodes for relatives to that codes and adds them to the DoNotPromote Field.
So, my question is, since I am updating the PermissionCodes field at the same time I am referencing it in the dbo.AddDoNotPromte UDF, when during the update statement is the PermissionCodes field being read within the dbo.AddDoNotPromote UDF? So far I am getting the results that I was hoping for, but is it always guaranteed that dbo.AddDoNotPromote will read the values in the PermissionCodes field before dbo.RemovePermissions removes those values?