Morning,
I have two tables. The first table (SecurityRules) is a list of security rules:
ID srRight srRole
1 4 NULL
2 2 32
The second table (Projects) is a list of Projects :
ProjId prRight prRole
1 0 NULL
2 0 32
3 0 NULL
I need to update the list of projects with all the records from SecurityRules and update the prRight
column based on the Role from both tables. The Right
values are bitwise-organised.
I used the following SQL update query to do this:
Update Projects
-- Perform binary sum
Set prRight = prRight | srRight
From SecurityRules
Where (srRole is Null) --Always apply srRight if srRole is not defined
OR (srRole is Not Null And srRole=prRole) --Apply right if both roles are equal
The expected result is:
ProjId prRight prRole
1 4 NULL
2 6 32
3 4 NULL
But I get:
ProjId prRight prRole
1 4 NULL
2 4 32
3 4 NULL
It looks like the update is done only by the first record of the SecurityRules table. And I need to apply all the records from the SecurityRules table to all records of the Project table. If I create a simple loop and manually looped all the records from SecurityRules it is working fine, but the performance is very poor if you have to compare 10 security rules to 2000 projects...
Any suggestion?
Arno