3

i've succesfully created db and tables, but when i try populate one of a table, like this

INSERT INTO Products(IsProductActive,ProductName,ProductCount) 
VALUES(0,'productName1',0),
      (0,'productName2',0),
      (1,'productName3',9),
      (1,'productName4',7),
      (1,'productName5',3),
      (1,'productName6',10),
      (0,'productName7',0),
      (1,'productName8',6),
      (1,'productName9',12),
      (1,'productName10',20);
GO

i got an error:

Msg 102, Level 15, State 1,

Line 2 Incorrect syntax near ','.

firstly which ',' is meant, secondly - what is wrong? PS: i use MS Management Studio v 9.0 if it is needed...

Community
  • 1
  • 1
Sergii
  • 1,017
  • 1
  • 10
  • 19
  • 1
    Table Value Constructors; SQL 2008 onward only; http://technet.microsoft.com/en-us/library/dd776382(v=sql.100).aspx – Alex K. Jan 23 '13 at 12:47

2 Answers2

3

Versions of SQL Server 2005 and below do not support the multiple VALUE clause syntax

SQL Server 2005 is version 9...

See How do I insert multiple rows WITHOUT repeating the "INSERT INTO dbo.Blah" part of the statement? for more

Community
  • 1
  • 1
gbn
  • 422,506
  • 82
  • 585
  • 676
0

if you are using SQL SERVER 2005 and below, the query wouldn't work because it doesn't support multiple value clause insert statement. You should insert it one by one.

Like this one below,

INSERT INTO Products(IsProductActive,ProductName,ProductCount) 
VALUES(0,'productName1',0)
GO
INSERT INTO Products(IsProductActive,ProductName,ProductCount) 
VALUES(0,'productName2',0)
GO
John Woo
  • 258,903
  • 69
  • 498
  • 492