如何将日期参数传递给MDX where子句和子查询

时间:2017-03-04 08:12:06

标签: subquery where mdx

我有一个查询,我想在where子句和子查询中参数化地成为日期。 我该怎么做? 当我在with子句中定义一个set时,我不能在where子句和子查询中使用它。

我的主要问题是:

 WITH
SET [countOfProple] As
  filter ([VW Dim Customer Broker Branch].[Customer BK].[Customer BK],[Measures].[Trade Cnt]>0)

  member [measures].[numbers] AS
  count([countOfProple])

select
[measures].[numbers] on 0

    from (
            select 

             {[VW Dim Customer Broker Branch].[Customer BK].[Customer BK]*[VW Dim Customer Broker Branch].[Reception Date].&[2006-09-23T00:00:00]:[VW Dim Customer Broker Branch].[Reception Date].&[2009-08-30T00:00:00]} on 0
             from [DV Present]
        )
     where [Vw Dim Date].[Gregorian Date].&[2006-09-23T00:00:00]:[Vw Dim Date].[Gregorian Date].&[2009-08-30T00:00:00];

当我从下面更改它时,它会有错误:

 WITH
SET [countOfProple] As
  filter ([VW Dim Customer Broker Branch].[Customer BK].[Customer BK],[Measures].[Trade Cnt]>0)

SET Date1 AS
[VW Dim Customer Broker Branch].[Reception Date].&[2006-09-23T00:00:00]:[VW Dim Customer Broker Branch].[Reception Date].&[2009-08-16T00:00:00]

SET Date2 AS
[Vw Dim Date].[Gregorian Date].&[2006-09-23T00:00:00]:[Vw Dim Date].[Gregorian Date].&[2009-08-16T00:00:00];

  member [measures].[numbers] AS
  count([countOfProple])

select
[measures].[numbers] on 0

    from (

            select 

             {[VW Dim Customer Broker Branch].[Customer BK].[Customer BK]*Date1} on 0
             from [DV Present]
        )
     where Date2

1 个答案:

答案 0 :(得分:0)

我假设"日期2"是你的参数。

您需要使用以下功能之一:

然后在这些函数中,您需要构建一个字符串来表示成员或集合的全名,包括amersand。

如果我们在字符串中进行硬编码,它将看起来像下列之一:

对于成员参数:

WHERE
  StrToMember('[Vw Dim Date].[Gregorian Date].&[2009-08-30T00:00:00]')  

对于设定参数:

WHERE
  StrToMember('[Vw Dim Date].[Gregorian Date].&[2006-09-23T00:00:00]:[Vw Dim Date].[Gregorian Date].&[2009-08-30T00:00:00]') 

如果使用say ssrs并且我们有一个参数@DtString,它可以采用两个结束日期值之一" 2009-08-30"或" 2010-08-30"然后我们可以将设置版本设置为动态如下:

WHERE
  StrToMember('[Vw Dim Date].[Gregorian Date].&[2006-09-23T00:00:00]:[Vw Dim Date].[Gregorian Date].&[' + @DtString + 'T00:00:00]')