0

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 ')'.

1 Answer 1

2

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

INSERT INTO @Companies 
            (field1, 
             field2) 
SELECT @newidentity, 
       Name 
FROM   Company 
WHERE  Name = 'Parker' 

What @Companies is?

Sign up to request clarification or add additional context in comments.

2 Comments

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 - Yes you can. It is the brackets around the select that were the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.