2

I'm trying to insert data into a table using a few columns that are hard-coded or are static values and then the rest of the datat selected from another table. I've tried the following query:

insert into wtdocversion 
values (( select id from wtdocmaster),'col2','col3');

But this generates an error:

Msg 512, Level 16, State 1, Line 1

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

5

You want to drop the values part of the query and do an INSERT\SELECT.

This is really basic SQL and you can read more about it in BOL.

INSERT INTO wtdocversion (col1, col2, col3)
SELECT
  id,
  'col2',
  'col3'
FROM wtdocmaster;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.