我显然不明白这一切是如何运作的。谢谢大家,对不起,对不起。
原帖:
我试图完成一些非常简单的事情,而且我在网上看到的每个地方都给出了一个语法,它会返回错误并且不会执行。
此代码执行:
declare @tester table (col1 varchar(max))
insert into @tester (col1) values ('abc')
select * from @tester
但由于某些原因,当我向值部分添加更多内容时,我会在'附近找到"不正确的语法。'。"
declare @tester table (col1 varchar(max))
insert into @tester (col1) values ('abc'), ('dcef')
select * from @tester
我尝试使用的一个在线资源是这个答案: Inserting multiple rows into a SQL Server table using a table variable
此修改有效,但我无法弄清楚为什么我只能为一系列值找出我的语法。
declare @tester table (col1 varchar(max))
insert into @tester (col1) values ('abc')
insert into @tester (col1) values ('dcef')
select * from @tester
答案 0 :(得分:0)
您必须使用select
插入许多记录,并union all
将它们放在文字列表与其他表格中的选择中。
以下是一个例子:
declare @tester table (col1 varchar(max));
insert into @tester (col1)
Select 'abc' union all
'dcef' union all
'ghi';
select * from @tester;
分号分隔符是可选的。