使用Power Query在Excel中将参数传递到MDX查询

huangapple go评论88阅读模式
英文:

Passing a parameter into an MDX Query using Power Query in Excel

问题

我正在使用一个参数来构建一个MDX查询到SQL Server Cube/Tabular Model的分析服务中。这是一个示例

AnalysisServices.Database("server_name", db_param, [Query = "SELECT * FROM table_a WHERE db = 'db_name'"])


我的参数是'db_param',它可以正常工作,用于建立与服务器内正确数据库的连接,但我无法将其传递给MDX查询。我希望能够将'db_name'替换为db_param,以便调用该参数。

有什么想法吗?我尝试过单括号、双括号、放在引号内、不放在引号内。我似乎也无法创建一个链条(例如:"SELECT * FROM table_a WHERE db = " + db_param + "查询的其余部分")。

有什么想法吗?
英文:

I am using a parameter to build an MDX query to analysis services in a SQL Server Cube/Tabular Model. This is an example

AnalysisServices.Database("server_name", db_param, [Query = "SELECT * FROM table_a WHERE db = 'db_name'])

My parameter is 'db_param', and it works fine to build the connection to the right database inside the server, but I can't manage to pass it to the MDX query. I would essentially like to replace 'db_name' with db_param such that it calls the parameter.

Any ideas? I tried single brackets, double brackets, inside quotation marks, not inside quotation marks. And I can't seem to create a chain either. (e.g. "SELECT * FROM table_a WHERE db = " + db_param + "rest of the query"]

Any ideas?

答案1

得分: 1

一般情况下,您需要使用 & 而不是 + 来进行组合。

let aa = "ddd",
    bb = "ccc",
    statement = "SELECT * FROM " + aa + " WHERE db='" + bb + "'",
    Source = [Query = statement]
in Source
英文:

In general, you need to use & not + to combine.

let aa = "ddd", 
bb= "ccc", 
statement = "SELECT * FROM "&aa& " WHERE db='"&bb&"'", 
Source =[Query = statement]
in Source

huangapple
  • 本文由 发表于 2023年7月6日 20:41:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76628943.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定