问题
Here is my script:
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]
I know that [Set_TargetEmp]
is the following:
So why when I wrap it in the function DESCENDANTS
with the optional arg SELF_BEFORE_AFTER
isn't reuben's related Department and Title not returned ?
EDIT
So I've simplified the above even further. Why doesn't the following return Reuben's title and department - I thought the point of SELF_BEFORE_AFTER
was to also return relatives from the other levels of the hierarchy [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]
回答1:
Descendants
only returns descendants, i. e. members on a lower level than the first argument. What you require would be an Ancestor. But - according to the documentation - the Ancestor
and Ancestors functions do not allow a set as first argument. This means that - assuming your set is meant to possibly contain more than one member - you would have to use Generate to iterate over the members of [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]
来源:https://stackoverflow.com/questions/21026900/self-before-after-why-arent-members-from-related-levels-returned