SSAS数据源视图变量

时间:2012-08-24 21:13:58

标签: tsql variables ssas dataview

我正在尝试使用“新命名查询”在SSAS中的数据源视图中添加表。该脚本如下所示:

Declare @AvgInvestment float;
SELECT  @AvgInvestment=SUM(Investment)/COUNT(distinct meta_ID)
FROM AAAA



SELECT        Player, Investment, 
              InvestmentRange=
              Case When Investment >=0 AND  Investment <(@AvgInvestment/3)                       THEN 1
                   When Investment >=(@AvgInvestment/3) AND  Investment <(4*@AvgInvestment/3)    THEN 2                           
                   When Investment >=(4*@AvgInvestment/3) AND  Investment <(6*@AvgInvestment/3)  THEN 3                         
                   When Investment >=(2*@AvgInvestment)                                          THEN 4
             END                              
FROM  AAAA 

但是,SSAS不允许在SQL查询中为DVS声明变量。有没有可能的方法来修改SQL语句没有变量?我试图将@AvgInvestment替换为“SELECT SUM(投资)/ COUNT(不同的meta_ID)从AAAA”,但它不起作用。

感谢任何可能的解决方案!

1 个答案:

答案 0 :(得分:1)

您可以使用变量加入平均值。例如:

SELECT Player, Investment, 
       InvestmentRange=
       Case When Investment >=0 AND  Investment <(a.avg/3)              THEN 1
            When Investment >=(a.avg/3) AND  Investment <(4*a.avg/3)    THEN 2
            When Investment >=(4*a.avg/3) AND  Investment <(6*a.avg/3)  THEN 3                         
            When Investment >=(2*a.avg)                                 THEN 4
       END                               
FROM  AAAA cross join 
(select SUM(Investment)/COUNT(distinct meta_ID) as avg from aaaa) a

在数据源视图中完美运行。存储过程不适用于那里。