Bit Masking
Bit Masking
FOLKS Table
PersonKey Roles Name
----------- -------------------- ----------------------------------
1 3 Ray's XRay
2 1 Accurate Imaging
3 7 Universal Pictures
4 16 CIGNA
5 16 BCBS-TN
ROLES Table
RoleKey RoleDescription
----------- --------------------------------------------------------
0 Undefined
1 Facility
2 FacilityGroup
4 ParentCompany
8 PayerGroup
16 Payer
32 Team Lead
64 PSA
128 Director
RESULTS
PersonKey Roles Name
----------- -------------------- ------------------------- --------------------------------------
1 3 Ray's XRay Facility,FacilityGroup
2 1 Accurate Imaging Facility
3 7 Universal Pictures Facility,FacilityGroup,ParentCompany
4 16 CIGNA Payer
5 16 BCBS-TN Payer
Functions
CREATE FUNCTION dbo.uftBitmaskedValues (
@Value int
)
RETURNS TABLE
AS
RETURN
SELECT
POWER(2, Counter - 1) [KeyValue]
FROM
dbo.Sequence
WHERE
@Value & POWER(2, Counter - 1) = POWER(2, Counter - 1) AND
Counter < 30
SELECT
@Roles = COALESCE(@Roles + ',', '') + Roles.RoleDescription
FROM
dbo.uftBitmaskedValues(@iRoles) A JOIN
dbo.Roles ON A.KeyValue=Roles.RoleKey
Return @Roles
End