下午全部。
我正在构建一个Web应用程序,我正在尝试从SSAS多维数据集中提取一些数据。
我有以下MDX我希望在c#中复制,但添加了一些参数,即两个参数,一个用于公司123,另一个用于位置1:
@"SELECT NON EMPTY([Dim Unit].[All Units].[Category Group Name]) ON COLUMNS
FROM [Info]
WHERE ([Dim Company].[All Companies].&[123],
[Dim Location].[All Locations].&[123]&[1])";
现在,我可以使用一个参数启动并运行:
AdomdCommand cmdPDC = conPDC.CreateCommand();
cmdPDC.CommandText = "SELECT [Dim Unit].[All Units].[Category Group Name].Members ON 0 FROM [Info] WHERE (StrToMember(@P1)";
string companyid = "123";
string sP1 = "[Dim Company].&" + company;
cmdPDC.Parameters.Add(new AdomdParameter("P1", sP1));
但是,如何实现第二个参数,例如,如果我想在参与位置中添加参数?我正沿着下面的思路思考,但我无法让小小的草皮工作:
AdomdCommand cmdPDC = conPDC.CreateCommand();
cmdPDC.CommandText = "SELECT [Dim Unit].[All Units].[Category Group Name].Members ON 0 FROM [Info] WHERE (StrToMember(@P1)," + "(StrToMember(@P2))";
string companyid = "123";
string locationid = "1";
string sP1 = "[Dim Company].&" + company;
string sP2 = "[Dim Location].&" + company + "&" + location;
cmdPDC.Parameters.Add(new AdomdParameter("P1", sP1));
cmdPDC.Parameters.Add(new AdomdParameter("P2", sP2));
感激不尽的任何帮助或建议。
答案 0 :(得分:4)
解决方案!
AdomdCommand cmdPDC = conPDC.CreateCommand();
cmdPDC.CommandText = "SELECT NON EMPTY [Dim Unit].[All Units].[Category Name].Members ON 0 FROM [MY CUBE] WHERE (StrToMember(@CompanyId),StrToMember(@LocationId))";
string companyid = "[123]";
string locationid = "[1]";
string sCompanyId = "[Dim Company].&" + companyid;
string sLocationId = "[Dim Location].&" + companyid + "&" + locationid;
cmdPDC.Parameters.Add(new AdomdParameter("CompanyId", sCompanyId));
cmdPDC.Parameters.Add(new AdomdParameter("LocationId", sLocationId));
还有一些小指示。
您可能会收到此错误:
“无法解析X参数,因为它在内部子表达式中被引用”
解决方案:在引用的字符串中插入@CompanyId
时,请确保参数未包含在撇号(')中 - c#很聪明并将转换数据类型并为您添加这些撇号。但是,您将无法在观察窗口中看到它,一切看起来都没问题。
返回所有项目,看起来您的参数被忽略。
解决方案:检查第一个SELECT
并确保它是SELECT NON EMPTY
。
答案 1 :(得分:0)
SELECT NON EMPTY {
[Measures].[Phone Count],
[Measures].[Mail Count],
[Measures].[Individual Count]
} ON COLUMNS
FROM [PyramidReports-US]
WHERE (
(STRTOSET(@PoliticalGeographyByCD),
[Political Geography].[By CD].[State].currentmember ),
(STRTOSET(@GenderGender),
[Gender].[Gender].currentmember ),
(STRTOSET(@ModelAffinityAffinityQuartile),
[Model Affinity].[Affinity Quartile].currentmember
)
使用currentmember填充参数这样的查询怎么样?