gpt4 book ai didi

sql - MS Access 插入多行

转载 作者:行者123 更新时间:2023-12-01 13:32:59 25 4
gpt4 key购买 nike

对于一个项目,我想使用查询将多行插入到表中。我发现了几个关于如何做到这一点的话题,例如 this one ,这真的很有帮助,但我仍然无法弄清楚如何插入多行。

我目前的 SQL 代码不会导致任何语法错误,但它不会插入任何行。

我要插入的表如下所示:

create table SYT_ABRDAT
(
id integer primary key not null,
beginper integer,
eindper integer,
periode text,
groep bit
)

我当前使用的查询(我缩短了它):

insert into syt_abrdat (id, begindat, einddat, periode, groep) 
select *
from
(select top 1
"1" as id, "9999" as begindat, "9999" as einddat,
"---" as periode, "1" as groep
from
onerow
union all
select top 1
"2" as id, "9999" as begindat, "9999" as einddat,
"XXX" as periode, "1" as groep
from
onerow
)

解决方法:

我在表 onerow 中添加了一个空行,而不是用一些数据填充它。

这是必要的

最佳答案

INSERT INTO syt_abrdat (id,begindat,einddat,periode,groep) 
SELECT * FROM
(SELECT TOP 1 1 AS id, 9999 AS begindat, 9999 as einddat, '---' as periode, 'WAAR' as groep FROM onerow UNION ALL
SELECT TOP 1 2 AS id, 9999 AS begindat, 9999 as einddat, 'XXX' as periode, 'WAAR' as groep FROM onerow)

评论:

  • 对文字字符串值使用单引号
  • 不要对文字数字使用引号
  • onerow 必须至少包含 1 条记录

关于sql - MS Access 插入多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44761882/

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