Take the 2-minute tour ×

I can't figure out what in the world this is complaining about, looks fine to me:

DECLARE @newidentity int 
SET @newidentity = scope_identity()
select @newidentity

Insert into @Companies (select @newidentity, Name from Company where Name = 'Parker')

I get the following for the insert line:

Incorrect syntax near the keyword 'select'.
Incorrect syntax near ')'.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Try it without brackets and specify fields of companies, please:

INSERT INTO @Companies 
SELECT @newidentity, 
FROM   Company 
WHERE  Name = 'Parker' 

What @Companies is?

share|improve this answer
hmm so with table variables you can't use the shortcut of leaving out the field definitions before you specify the fields to be selected for insert? –  CoffeeAddict May 27 '12 at 15:34
@CoffeeAddict - Yes you can. It is the brackets around the select that were the problem. –  Martin Smith May 27 '12 at 16:31
add comment

Your Answer


