如何调用VBA函数以指定SQL TRANSFORM查询中的列? [英] How to call VBA-function for specifying columns in SQL TRANSFORM query?
问题描述
这是我的查询:
PARAMETERS ...
TRANSFORM ...
SELECT ...
...
PIVOT Mytable.type In ("Other","Info");
这是一个交叉查询,我需要在该行中设置所有列标题:PIVOT Mytable.type In ("Other","Info")
,现在我已经硬编码了标题, Other 和 Info .
This is a cross query and I need to set all the column headings with this row: PIVOT Mytable.type In ("Other","Info")
and now I have hard-coded the headings, Other and Info.
但是我想动态地做到这一点.所以我想做的就是调用一个vba函数,该函数返回我需要的所有标题.
But I want to do this dynamically. So what I want to do is to call a vba-function that returns all the headings I need.
类似这样的东西:
PIVOT Mytable.type In (myVbaFunction());
所以我的问题是:如何在sql查询中调用vba函数?
So my question is: How to call a vba-function inside the sql-query?
推荐答案
是的,有可能.
但是,我认为WHERE IN (...)
不可能.
Yes, it is possible.
However, I don't think it's possible with WHERE IN (...)
.
以下是普通WHERE
查询的示例:
Here is an example for a normal WHERE
query:
Public Function Test() As String
Test = "Smith"
End Function
...然后:
SELECT * FROM Users WHERE Name = Test();
它起作用,只要该函数仅返回一个值即可.
但是我认为不可能让您的函数返回"Smith,Miller"之类的东西并使用类似这样的东西:
It works, as long as the function only returns one value.
But I think it's not possible to let your function return something like "Smith, Miller" and use that like:
SELECT * FROM Users WHERE Name In (Test());
(至少我不知道该怎么做)
(at least I don't know how to do it)
这篇关于如何调用VBA函数以指定SQL TRANSFORM查询中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!