sql - 使用变量 append 字段参数

标签 sql parameters append ado

交叉张贴在这里:

http://www.vbforums.com/showthread.php?696163-Use-variable-to-append-field-parameter&p=4264077#post4264077

我正在使用 ADO 将 MS Access 中的数据检索到 Excel 中,并且我想将 Iif 语句 append 到查询的 SELECT 部分。我的 SQL 字符串存储在一个文本文件中,所有参数都通过 ADO append 。

我知道如何在 WHERE 子句中 append 参数,甚至可以在 SELECT 语句中 append 参数,如下所示:

SELECT BA, Iif(QA=[@somestring],[@somestring2], [@somestring3])
FROM myData
WHERE BA = 'some person'

但我想要完成的是将占位符 [@somestring] 转换为可变长度的 Iif 语句,例如:
SELECT BA, [@somestring]    

占位符转换为我使用函数构建的字符串:
Iif(QA='Jon Doe', 'Jon', Iif(QA='Jane Doe', 'Jane', 'Nobody')).  

现在,我得到的结果是我传递给填充整个字段的参数的文字字符串。所以 Iif 语句是为每条记录写出的,而不是由 SQL 评估的。

我正在尝试做的事情是否可能,或者 SQL 是否需要在初始命令中预定义的 Iif 语句的字段?

即,Iif(QA=[@somestring], [@sometstring2], [@somestring3])

最佳答案

这是来自 VBForums 的直接剪切和粘贴。它是一个社区 wiki,只打算从“没有答案”中删除这个问题。可酌情删除或修改。

发件人:http://www.vbforums.com/showthread.php?696163-Use-variable-to-append-field-parameter&p=4264077#post4264077

BY: si_the_geek

It isn't possible, you can only use parameters to set Values, you can't do other things with them (such as field/table names, functions, etc).

If you want to alter the other parts of the query, you'll need to use other methods (such as string building). In the example at the end of your post, you should add that to the query string, and add the values via parameters.

关于sql - 使用变量 append 字段参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13034479/

相关文章:

python - 访问 python json key 时需要传递参数

powershell - 是否可以在另一个脚本中调用 powershell 脚本作为变量?

c++ - DirectX 11 append 缓冲区字节宽度

python - 将行 append 到 Pandas DataFrame 添加 0 列

python - 在 pandas 上追加后仅保留重复的索引

mysql - SQL 内连接到左连接表

sql - 在 MSSQL 中将每个数值增加 15%

python - 不确定如何验证我的 api key Kucoin

mysql - 级联删除,如 ON DELETE CASCADE 用于 MySQL 中的一次性操作

SQL 服务器 : weird Invalid object name