【问题标题】:Querying OLAP server查询OLAP服务器
【发布时间】:2012-04-02 22:19:30
【问题描述】:

我使用以下代码在 C# 中执行查询:

 AdomdConnection con = new AdomdConnection("Datasource=local;...");

            con.Open();
            AdomdCommand command = con.CreateCommand();
            command.CommandText = input;

            AdomdDataReader reader = command.ExecuteReader();
  while (reader.Read())
            {
for(i =0; i<reader.fieldCount; i++){
      a[i]=reader.GetString(i);
}
return a;

但是,此代码返回层次结构中每个单元格的完整路径。即,每一行数据类似于 [AllGeography, Canada, Vancouver, Allproduct, bikes, Accessories, 297483]。 我只想检索叶子和测量值:[温哥华,附件,297483]。我该怎么办?如何指定叶子?

【问题讨论】:

    标签: c# ado.net mdx olap


    【解决方案1】:

    因为 MDX 查询的结果实际上是多维的,所以我觉得自己使用 ExecuteCellSet 更舒服。您可以获取整个 CellSet,然后通过坐标获取Measures。

    例如(如果您在查询中有一个度量):

    AdomdCommand cmd = conn.CreateCommand();
    cmd.CommandText = @"SELECT 
                [Geography].[Geography].[Country].&[Canada].Children ON 0, 
                [Product].[Id] ON 1
                FROM [Cube]
                WHERE [Measures].[Your Measure]";
    
    CellSet cs = cmd.ExecuteCellSet();
    
    TupleCollection CanadaChildren = cs.Axes[0].Set.Tuples;
    TupleCollection ProductIds = cs.Axes[1].Set.Tuples;
    
    for (int row = 0; row < CanadaChildren.Count; row++)
    {
        for (int col = 0; col < ProductIds.Count; col++)
        {
            a[i++] = cs.Cells[col, row].Value;
        }
    }
    conn.Close();
    

    如果您有多个度量,则它将是查询中的第三个维度和单元集中的第三个坐标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-03
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多