I have two tables of same structure and want to insert rows from tableA into tableB.
The following example works fine:
INSERT INTO tableA (uniqueColA, colB, colC)
SELECT uniqueColA, colB, colC FROM tableB
WHERE uniqueColA = 1
However, if the SELECT returns more than one row, like
INSERT INTO tableA (uniqueColA, colB, colC)
SELECT uniqueColA, colB, colC FROM tableB
WHERE uniqueColA IN (1,2)
SQL Server returns the error
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Why that, and how can I solve this?
EDIT: The parentheses around the columns of the SELECT were a typo. Wether there are parentheses around the entire SELECT...WHERE... does not matter, it throws the same error.
(SELECT (uniqueColA, colB, colC) FROM ...<>SELECT (uniqueColA, colB, colC) .FROM...<>SELECT uniqueColA, colB, colC FROM.... The only places you should have parenthesis are in yourINSERTandINclauses.tableAwhich is not properly written to handle multiple rows. Remember that triggers fire once per statement rather than per row so the virtualinsertedtable in the trigger may contain multiple rows.