Insert multiple values using INSERT INTO

Posted by Ben McCormack on Stack Overflow See other posts from Stack Overflow or by Ben McCormack
Published on 2010-03-17T13:25:54Z Indexed on 2010/03/17 13:31 UTC
Read the original article Hit count: 328

Filed under:
|
|
|

In SQL Server 2005, I'm trying to figure out why I'm not able to insert multiple fields into a table. The following query, which inserts one record, works fine:

INSERT INTO [MyDB].[dbo].[MyTable]
           ([FieldID]
           ,[Description])
     VALUES
           (1000,N'test')

However, the following query, which specifies more than one value, fails:

INSERT INTO [MyDB].[dbo].[MyTable]
           ([FieldID]
           ,[Description])
     VALUES
           (1000,N'test'),(1001,N'test2')

I get this message:

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

When I looked up the help for INSERT in SQL Sever Management Studio, one of their examples showed using the "Values" syntax that I used (with groups of values in parentheses and separated by commas). The help documentation I found in SQL Server Management Studio looks like it's for SQL Server 2008, so perhaps that's the reason that the insert doesn't work. Either way, I can't figure out why it won't work.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server