Database Reference
In-Depth Information
9.3.4 Source Code of the View for Each Model of the
Multilevel Relational Database Models
The following SQL functions are used in the views of each model of
the multilevel relational database models:
CREATE FUNCTION [dbo].[SortLabels]()
RETURNS @Labels TABLE
(
Sort int,
LabelID int,
Label nvarchar(50)
)
AS
BEGIN
with RecursionCTE (Sort,Label)
as
(
select 0,ChildMarkingRoleName
from dbo.tblMarkingHierarchy
where ParentMarkingRoleName = '0'
union all
select R2.Sort+1,ChildMarkingRoleName
from dbo.tblMarkingHierarchy as R1
join RecursionCTE as R2 on R1.ParentMarkingRoleName =
R2.Label
)
insert into @Labels select RecursionCTE.Sort,dbo.
tblUniqueLabel.ID,RecursionCTE.Label from
RecursionCTE inner join dbo.tblUniqueLabel on
RecursionCTE.Label = dbo.tblUniqueLabel.Label
RETURN
END
GO
create FUNCTION [dbo].[GetUserLabel]()
RETURNS nvarchar(10)
AS
BEGIN
declare @Label nvarchar(10)
select @Label = g.name
from sys.database_principals u,
sys.database_principals g,
sys.database_role_members m
where g.principal_id = m.role_
principal_id
Search WWH ::




Custom Search