这是我的剧本:
WITH
SET [Set_TargetEmp] AS
{
FILTER(
[Employee Department].AllMembers,
(
InStr(
1,
[Employee].[Employee Department].currentmember.name,
"REUBEN") <> 0
)
)
}
SELECT
DESCENDANTS(
[Set_TargetEmp],
[Employee].[Employee Department],
SELF_BEFORE_AFTER)
ON 1,
{} ON 0
FROM [Adventure Works]
我知道[Set_TargetEmp]
如下:
那么为什么当我将它包含在带有可选arg DESCENDANTS
的函数SELF_BEFORE_AFTER
中时,不是reuben的相关部门和标题没有返回?
修改
所以我进一步简化了上述内容。为什么下面没有返回Reuben的标题和部门 - 我认为SELF_BEFORE_AFTER
的意思是还要从层次结构[Employee].[Employee Department]
的其他级别返回亲属?
SELECT
DESCENDANTS(
[Employee].[Employee Department].[Employee].[Reuben H. D'sa],
[Employee].[Employee Department],
SELF_BEFORE_AFTER)
ON 1,
{} ON 0
FROM [Adventure Works]
答案 0 :(得分:1)
Descendants
只返回后代,i。即比第一个参数更低级别的成员。你需要的是Ancestor
。但是 - 根据文档 - Ancestor
和Ancestors
函数不允许set作为第一个参数。这意味着 - 假设您的集合可能包含多个成员 - 您必须使用Generate
来迭代[Set_TargetEmp]
的成员:
WITH
SET [Set_TargetEmp] AS
{
FILTER(
[Employee Department].AllMembers,
(
InStr(
1,
[Employee].[Employee Department].currentmember.name,
"REUBEN") <> 0
)
)
}
SELECT
{} ON 0,
Generate([Set_TargetEmp] as e,
{Ancestor(e.Current, [Employee].[Employee Department].[Department])}
)
ON 1
FROM [Adventure Works]