2011-03-09 114 views
1

我需要将50多行插入到SQL Server 2008中,并且出现一个奇怪的错误。请帮忙!SQL SERVER 2008:尝试使用1个SQL语句插入多行

表设计:

  • 名称:mod_Facilities
    • faclityID,主键/索引
    • facilityName,为nvarchar(4000)
    • facilityDescription,为nvarchar(4000)
    • statusComment,nvarchar(4000)
    • isPublic,位
    • isActive,位
    • 请将isDeleted,位

错误:

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

这里是我的SQL语句

INSERT INTO mod_Facilites (facilityName,facilityDescription,isActive,isDeleted) 
VALUES 
('Conference Room Lower','Conference Room Lower – 25, (AV ready for meetings and info sessions)','true','false'), 
('Conference Room Upper','Conference Room Upper – 21, (AV ready for meetings and info sessions)','true','false'), 
('Meeting Room A','Meeting Room A – (upper theatre set up capacity 40) ','true','false'), 
('Meeting Room B','Meeting Room B – (AV ready classroom set up capacity 25) ','true','false'), 
('Meeting Rooms A & B','Meeting Rooms A & B – (AV ready capacity 80)','true','false'), 
('OP Resource Room','OP Resource Room','true','false'), 
('Climbing Wall','Climbing Wall','true','false'), 
('Bouldering Wall','Bouldering Wall','true','false'), 
('Entire Climbing Area','Entire Climbing Area','true','false'), 
('CPR/First Aid classroom','CPR/First Aid classroom','true','false'), 
('Lobby Area','Lobby Area','true','false'), 
('Studio 1','Studio 1 ','true','false'), 
('Studio 2','Studio 2','true','false'), 
('Studio 3','Studio 3','true','false'), 
('Studio 4','Studio 4','true','false'), 
('Mat Studio','Mat Studio','true','false'); 
+3

对于那些不熟悉,这是在SQL Server中有效语法2008年。但对于以前版本的SQL Server,您必须使用不同的方法。 – DOK 2011-03-09 17:50:08

+1

因为你传递了var的isActive和isDeleted? – 2011-03-09 17:51:54

+0

如果你通常尝试'('Mat Studio','Mat Studio',true,false)'(围绕你的BIT值没有单引号) - 这会改变什么吗? – 2011-03-09 18:03:36

回答

4

你标记这个问题为SQL Server 2008,但是如果你在2005年或更早的时候尝试过这种语法,那么它就是你所看到的错误。

作为替代方案,尝试:

INSERT INTO mod_Facilites 
    (facilityName,facilityDescription,isActive,isDeleted) 
    SELECT 'Conference Room Lower','Conference Room Lower – 25, (AV ready for meetings and info sessions)','true','false' UNION ALL 
    SELECT 'Conference Room Upper','Conference Room Upper – 21, (AV ready for meetings and info sessions)','true','false' UNION ALL 
    SELECT 'Meeting Room A','Meeting Room A – (upper theatre set up capacity 40) ','true','false' UNION ALL 
    SELECT 'Meeting Room B','Meeting Room B – (AV ready classroom set up capacity 25) ','true','false' UNION ALL 
    SELECT 'Meeting Rooms A & B','Meeting Rooms A & B – (AV ready capacity 80)','true','false' UNION ALL 
    SELECT 'OP Resource Room','OP Resource Room','true','false' UNION ALL 
    SELECT 'Climbing Wall','Climbing Wall','true','false' UNION ALL 
    SELECT 'Bouldering Wall','Bouldering Wall','true','false' UNION ALL 
    SELECT 'Entire Climbing Area','Entire Climbing Area','true','false' UNION ALL 
    SELECT 'CPR/First Aid classroom','CPR/First Aid classroom','true','false' UNION ALL 
    SELECT 'Lobby Area','Lobby Area','true','false' UNION ALL 
    SELECT 'Studio 1','Studio 1 ','true','false' UNION ALL 
    SELECT 'Studio 2','Studio 2','true','false' UNION ALL 
    SELECT 'Studio 3','Studio 3','true','false' UNION ALL 
    SELECT 'Studio 4','Studio 4','true','false' UNION ALL 
    SELECT 'Mat Studio','Mat Studio','true','false'; 
+0

虽然这可能很好地解决了OP中的问题。我会更关心为什么MSSQL 2008不像MSSQL 2008那样行事。 – Enull 2011-03-09 20:42:23

4

你在SQL 2008兼容模式下运行?

这会返回100还是小于100?如果低于100,那么你没有在SQL 2008的兼容性级别运行

SELECT compatibility_level 
FROM sys.databases 
WHERE database_id = DB_ID() 
+0

我该如何检查? – 2011-03-09 17:47:08

+0

查看附加代码。 – SQLMenace 2011-03-09 17:48:05

0

有它必须是一个陈述任何理由?我从来没有见过这种INSERT语句的使用。我会使用多个语句或BULK INSERT或SSIS。

+0

你有一个批量插入的例子吗? – 2011-03-09 17:52:47

+0

链接MSDN增加 - 这取决于你的数据源,以它是否是最好的BULK INSERT或SSIS但基本上BULK INSERT将文件的内容插入表。 SSIS可以贴任何东西,任何地方:) – 2011-03-09 17:55:30

0

处理这个最简单的方法是改变值到选择和UNION他们:

INSERT INTO mod_Facilites (facilityName,facilityDescription,isActive,isDeleted) 
SELECT 
    'Conference Room Lower', 'Conference Room Lower – 25, (AV ready for meetings and info sessions)','true','false' UNION ALL 
SELECT 
    'Conference Room Upper','Conference Room Upper – 21, (AV ready for meetings and info sessions)','true','false' UNION ALL 

...等