gpt4 book ai didi

sql-server - 将多个值插入临时表,SQL Server

转载 作者:行者123 更新时间:2023-12-03 01:24:00 25 4
gpt4 key购买 nike

我正在使用 Microsoft SQL Server Management Studio,我正在尝试运行以下查询以将值输入到临时表中以供稍后使用:

CREATE TABLE #temptable
(colnumber varchar(15), dispcode varchar(10))

INSERT INTO #temptable (colnumber, dispcode)
VALUES
('col5', '811'),
('col6', '817'),
('col7', '823'),
('col8', '825');

运行时出现以下错误:

Msg 102, Level 15, State 1, Line 50
Incorrect syntax near ','.

指向行“('col5', '811'),”

谁能帮我找出问题所在吗?

最佳答案

对于 SQL Server 版本 <2008,请使用此:

INSERT INTO #temptable (colnumber, dispcode)
SELECT 'col5', '811'
UNION ALL SELECT 'col6', '817'
UNION ALL SELECT 'col7', '823'
UNION ALL SELECT 'col8', '825'

关于sql-server - 将多个值插入临时表,SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18000115/

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