我在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
SELECT 21, 15917, {ts '2012-02-09 14:08:28'}, 42126
UNION ALL
SELECT 21, 17052, {ts '2012-02-09 14:08:28'}, 42126
但它只向数据库插入一行。当我在查询分析器中运行查询时,它插入3行。我在实际声明中使用了循环和查询参数,但即使这个版本也失败了。
我正在使用此代码在另一台服务器上插入数据,它工作正常,但这里甚至是
INSERT INTO TABLE (ID)
SELECT ID FROM TABLE1
只插入一行。
数据库服务器是MSSQL 2000
我尝试在我的DSN中找到一个设置,但没有什么能让我知道为什么它不能正常工作
答案 0 :(得分:2)
尝试将SELECT子查询包装在括号中,看看是否有帮助。
答案 1 :(得分:0)
我认为UNION ALL语句是个问题。首先,您一次尝试插入多少行?您是否尝试过此处提供的MySQL兼容解决方案:
How to Execute 2 or more insert statements using CFQuery in coldfusion?
你在运行什么版本的ColdFusion?
答案 2 :(得分:0)
尝试命名列并将联合放在子查询中:
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