SQL Server 2008中MDX的DRILLDOWNLEVEL函数参数过多异常求助
解决SQL Server 2008中MDX DRILLDOWNLEVEL参数过多的问题
我之前也碰到过这个问题,核心原因很明确:SQL Server 2008的MDX引擎里,DRILLDOWNLEVEL函数最多只支持3个参数,而你用到的INCLUDE_CALC_MEMBERS是SQL Server 2012及更高版本才新增的第四个参数,所以2008版本会直接抛出参数过多的错误,而高版本能正常识别执行。
给你两种可行的解决方案:
方案1:使用DRILLDOWNLEVELINCLUSIVE替代(推荐)
SQL Server 2008原生支持DRILLDOWNLEVELINCLUSIVE函数,它的作用就是在钻取层级时自动包含计算成员,正好匹配你用INCLUDE_CALC_MEMBERS的需求。修改后的完整查询如下:
WITH MEMBER [Customer].[Customer Geography].[Country].&[United States].[West Coast] AS [Customer].[Customer Geography].[State-Province].&[OR]&[US] + [Customer].[Customer Geography].[State-Province].&[WA]&[US] + [Customer].[Customer Geography].[State-Province].&[CA]&[US] SELECT [Measures].[Internet Order Count] ON 0, DRILLDOWNLEVELINCLUSIVE([Customer].[Customer Geography].[Country].&[United States]) on 1 FROM [Adventure Works]
这个写法在SQL Server 2008中可以正常执行,同时在2014、2016等高版本也能兼容,不需要额外调整。
方案2:手动合并钻取结果与计算成员
如果你坚持要使用DRILLDOWNLEVEL,可以先获取钻取后的基础层级集合,再手动合并你的计算成员:
WITH MEMBER [Customer].[Customer Geography].[Country].&[United States].[West Coast] AS [Customer].[Customer Geography].[State-Province].&[OR]&[US] + [Customer].[Customer Geography].[State-Province].&[WA]&[US] + [Customer].[Customer Geography].[State-Province].&[CA]&[US] SELECT [Measures].[Internet Order Count] ON 0, { DRILLDOWNLEVEL([Customer].[Customer Geography].[Country].&[United States]), [Customer].[Customer Geography].[Country].&[United States].[West Coast] } on 1 FROM [Adventure Works]
不过这种方法需要你明确指定要包含的计算成员,当计算成员较多时会比较繁琐,所以更推荐方案1。
内容的提问来源于stack exchange,提问作者Manikandan Ram
相关产品推荐
相关产品推荐

