Hi,
Below you find a small part of one filtered view. The full CREATE VIEW script is 1040 lines long.
--
-- report view for account
--
create view [dbo].[FilteredAccount] (
accountcategorycode,
accountcategorycodename,
accountclassificationcode,
accountclassificationcodename,
accountid,
accountnumber,
accountratingcode,
accountratingcodename,
address1_addressid,
address1_addresstypecode,
address1_addresstypecodename,
address1_city
) with view_metadata as
select
Account.AccountCategoryCode,
AccountCategoryCodePLTable.Value,
Account.AccountClassificationCode,
AccountClassificationCodePLTable.Value,
Account.AccountId,
Account.AccountNumber,
Account.AccountRatingCode,
AccountRatingCodePLTable.Value,
Account.Address1_AddressId,
Account.CreatedBy,
Account.CreatedByDsc,
Account.CreatedByName,
dbo.fn_UTCToTzSpecificLocalTime(Account.CreatedOn,
us.TimeZoneBias,
us.TimeZoneDaylightBias,
us.TimeZoneDaylightYear,
us.TimeZoneDaylightMonth,
us.TimeZoneDaylightDay,
us.TimeZoneDaylightHour,
us.TimeZoneDaylightMinute,
us.TimeZoneDaylightSecond,
0,
us.TimeZoneDaylightDayOfWeek,
us.TimeZoneStandardBias,
us.TimeZoneStandardYear,
us.TimeZoneStandardMonth,
us.TimeZoneStandardDay,
us.TimeZoneStandardHour,
us.TimeZoneStandardMinute,
us.TimeZoneStandardSecond,
0,
us.TimeZoneStandardDayOfWeek),
from Account
left join SystemUserBase u on (u.SystemUserId = dbo.fn_FindUserGuid() and u.IsDisabled = 0)
left join UserSettingsBase us on us.SystemUserId = u.SystemUserId
left join OrganizationBase o on u.OrganizationId = o.OrganizationId
left outer join StringMap AccountCategoryCodePLTable on
(AccountCategoryCodePLTable.AttributeName = 'accountcategorycode'
and AccountCategoryCodePLTable.ObjectTypeCode = 1
and AccountCategoryCodePLTable.AttributeValue = Account.AccountCategoryCode
and AccountCategoryCodePLTable.OrganizationId = o.OrganizationId
and AccountCategoryCodePLTable.LangId = o.LanguageCode )
left outer join StringMap AccountClassificationCodePLTable on
(AccountClassificationCodePLTable.AttributeName = 'accountclassificationcode'
and AccountClassificationCodePLTable.ObjectTypeCode = 1
and AccountClassificationCodePLTable.AttributeValue = Account.AccountClassificationCode
and AccountClassificationCodePLTable.OrganizationId = o.OrganizationId
and AccountClassificationCodePLTable.LangId = o.LanguageCode )
...
left outer join StringMap TerritoryCodePLTable on
(TerritoryCodePLTable.AttributeName = 'territorycode'
and TerritoryCodePLTable.ObjectTypeCode = 1
and TerritoryCodePLTable.AttributeValue = Account.TerritoryCode
and TerritoryCodePLTable.OrganizationId = o.OrganizationId
and TerritoryCodePLTable.LangId = o.LanguageCode )
cross join dbo.fn_GetMaxPrivilegeDepthMask(1) pdm
where Account.DeletionStateCode in (0)
and
(
-- privilege check
pdm.PrivilegeDepthMask is not null and
(
-- object owned by the user
--
Account.OwningUser = u.SystemUserId
-- role based access
or
exists
(
select
1
where
(
-- deep security
((pdm.PrivilegeDepthMask & 0x44) != 0) and
Account.OwningBusinessUnit in (select biz.SubBusinessId from BusinessUnitMap as biz where biz.BusinessId = u.BusinessUnitId)
)
or
(
-- global security
((pdm.PrivilegeDepthMask & 0x88) != 0) and
Account.OwningBusinessUnit is not null
)
or
(
-- local security
((pdm.PrivilegeDepthMask & 0x22) != 0) and
Account.OwningBusinessUnit = u.BusinessUnitId
)
)
-- object shared to the user
or
Account.AccountId in
(
select POA.ObjectId from PrincipalObjectAccess POA
join SystemUserPrincipals sup on POA.PrincipalId = sup.PrincipalId
where sup.SystemUserId = u.SystemUserId and
POA.ObjectTypeCode = 1 AND
((POA.AccessRightsMask | POA.InheritedAccessRightsMask) & 1)=1
)
)
)
GO
</Code>