如何从SQL查询内部调用VBA函数? [英] How to call VBA-function from inside sql-query?

查看:351
本文介绍了如何从SQL查询内部调用VBA函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的查询:

PARAMETERS ...
TRANSFORM ...
SELECT ...
...
PIVOT Mytable.type In ("Other","Info");

这是一个交叉查询,我需要设置所有的列标题使用此行: PIVOT Mytable.type在(其他,信息)现在我有硬codeD的标题,其他信息

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());

所以我的问题是:如何调用一个VBA函数的SQL查询里面

So my question is: How to call a vba-function inside the sql-query?

推荐答案

是的,这是可能的。
但是,我不认为这是可能的凡(...)

Yes, it is possible.
However, I don't think it's possible with WHERE IN (...).

下面是一个正常的,其中查询一个例子:

Here is an example for a normal WHERE query:

Public Function Test() As String
    Test = "Smith"
End Function

...然后:

...and then:

SELECT * FROM Users WHERE Name = Test();

它的工作原理,只要把函数只返回一个值。
但我认为它的不可以可以让你的函数返回类似史密斯,米勒并使用,如:

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)

这篇关于如何从SQL查询内部调用VBA函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆