gpt4 book ai didi

sql - 使用变量 append 字段参数

转载 作者:行者123 更新时间:2023-12-03 17:54:47 25 4
gpt4 key购买 nike

交叉张贴在这里:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com