使用 cfquery 时 INSERT/SELECT 语句仅插入一行
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将 SELECT 子查询括在括号中,看看是否有帮助。
Try wrapping your SELECT subqueries in parenthesis, see if that helps.
尝试命名列并将联合放入子查询中:
Try naming the columns and putting the unions in a subquery:
我认为 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?