使用 cfquery 时 INSERT/SELECT 语句仅插入一行

发布于 2025-01-03 18:25:52 字数 692 浏览 0 评论 0原文

我在 cfquery 标记内运行以下 SQL

INSERT INTO Meeting_RFPMeetings (RFP_ID, Meeting_ID, Inserted, Create_UserID)

SELECT 21, 15835, {ts '2012-02-09 14:08: 28'}, 42126

UNION ALL

选择21, 15917, {ts '2012-02-09 14:08:28'}, 42126

UNION ALL

选择 21, 17052, {ts '2012-02-09 14:08:28'}, 42126

但它只向 数据库。当我在查询分析器中运行查询时,它会插入 3 行。我在实际语句中使用了循环和查询参数,但即使这个版本也失败了。

我正在使用此代码在另一台服务器上插入数据,它工作正常,但这里即使是

INSERT INTO TABLE (ID)

SELECT ID FROM TABLE1

也只插入一行。

数据库服务器是 MSSQL 2000

我尝试在 DSN 中找到一个设置,但我没有发现为什么它不起作用

I'm running the following SQL inside a cfquery tag

INSERT INTO Meeting_RFPMeetings (RFP_ID, Meeting_ID, Inserted, Create_UserID)

SELECT 21, 15835, {ts '2012-02-09 14:08:28'}, 42126

UNION ALL

SELECT 21, 15917, {ts '2012-02-09 14:08:28'}, 42126

UNION ALL

SELECT 21, 17052, {ts '2012-02-09 14:08:28'}, 42126

but it only inserts one row to the database. When I run the query in Query Analyzer it inserts 3 row. I'm using a loop and queryparam's in my actual statement, but even this version fails.

I'm using this code to insert data on another server and it works fine, but here even a

INSERT INTO TABLE (ID)

SELECT ID FROM TABLE1

only inserts one row.

The database server is MSSQL 2000

I tried finding a setting in my DSN but nothing stood out to me as to why it wouldn't be working

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

婴鹅 2025-01-10 18:25:52

尝试将 SELECT 子查询括在括号中,看看是否有帮助。

Try wrapping your SELECT subqueries in parenthesis, see if that helps.

深海不蓝 2025-01-10 18:25:52

尝试命名列并将联合放入子查询中:

INSERT INTO Meeting_RFPMeetings (RFP_ID, Meeting_ID, Inserted, Create_UserID)
SELECT [1], [2], [3], [4]
FROM
(
SELECT 21 AS [1], 15835 AS [2], {ts '2012-02-09 14:08:28'} AS [3], 42126 AS [4]

UNION ALL

SELECT 21 AS [1], 15917 AS [2], {ts '2012-02-09 14:08:28'} AS [3], 42126 AS [4]

UNION ALL

SELECT 21 AS [1], 17052 AS [2], {ts '2012-02-09 14:08:28'} AS [3], 42126 AS [4]
) a

Try naming the columns and putting the unions in a subquery:

INSERT INTO Meeting_RFPMeetings (RFP_ID, Meeting_ID, Inserted, Create_UserID)
SELECT [1], [2], [3], [4]
FROM
(
SELECT 21 AS [1], 15835 AS [2], {ts '2012-02-09 14:08:28'} AS [3], 42126 AS [4]

UNION ALL

SELECT 21 AS [1], 15917 AS [2], {ts '2012-02-09 14:08:28'} AS [3], 42126 AS [4]

UNION ALL

SELECT 21 AS [1], 17052 AS [2], {ts '2012-02-09 14:08:28'} AS [3], 42126 AS [4]
) a
泪是无色的血 2025-01-10 18:25:52

我认为 UNION ALL 语句是问题所在。首先,您一次尝试插入多少行?您是否尝试过此处提供的兼容 MySQL 的解决方案:

如何在 Coldfusion 中使用 CFQuery 执行 2 个或多个插入语句?

您运行的 ColdFusion 版本是什么?

I think the UNION ALL statement is the problem. Firstly, how many rows are you trying to insert at a time? Have you tried the MySQL-compatible solutions offered here:

How to Execute 2 or more insert statements using CFQuery in coldfusion?

What version of ColdFusion are you running?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文