Reputation: 115
I've written the code below and keep getting an error for incorrect syntax
It said at line 10 near the ,
- so this line:
values(1, 'Stolz', 'Ted', 25000, NULL), )
If I only try to insert the first row of data it works fine, it's when I try to do multiple. Am I missing something really simple?
Drop Table #TPerson
CREATE TABLE #TPerson
(
personid int PRIMARY KEY NOT NULL,
lastname varchar(50) NULL,
firstname varchar(50) NULL,
salary money NULL,
managerid int NULL
);
Insert Into #TPerson(Personid, lastname, firstname, salary, managerid)
values (1, 'Stolz', 'Ted', 25000, NULL),
(2, 'Boswell', 'Nancy', 23000, 1),
(3, 'Hargett', 'Vincent', 22000, 1),
(4, 'Weekley', 'Kevin', 22000, 3),
(5, 'Metts', 'Geraldine', 22000, 2),
(6, 'McBride', 'Jeffrey', 21000, 2),
(7, 'Xiong', 'Jay', 20000, 3)
Upvotes: 0
Views: 62
Reputation: 3239
You can write something like this:
Insert Into #TPerson(Personid,lastname,firstname,salary,managerid)
select 1,'Stolz','Ted',25000,NULL
union all select 2,'Boswell','Nancy',23000,1
union all select 3,'Hargett','Vincent',22000,1
union all select 4,'Weekley','Kevin',22000,3
union all select 5,'Metts','Geraldine',22000,2
union all select 6,'McBride','Jeffrey',21000,2
union all select 7,'Xiong','Jay',20000,3
Upvotes: 1