I have to insert n-records based on a query and have to assign 7 values, comming from a second query.
Insert into table1 (ID, column1, column2,..., column7)
values (@ID, @column1, @column2,..., column7)
Query1 returns the ID (Format vector:1 x n)
Query2 returns the values for column1-7 (Format vector: 7 x 1) which do not vary for the n records
The correct matrix of values (Format 7 x n) is described by:
SELECT a.ID, b.column1, b.column2,..., b.column from
(SELECT ID from TABLE2) a
JOIN
(SELECT column1, column2,..., column7 from TABLE3) b on a.ID <> '0'
Unfortunatly I can't place this query into the INSERT clause likeInsert into table1 (ID, column1, column2,..., column7)
values ((SELECT a.ID, b.column1, b.column2,..., b.column from
(SELECT ID from TABLE2) a
JOIN
(SELECT column1, column2,..., column7 from TABLE3) b on a.ID <> '0'))It throws 2 errors:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS
and (this is NOT true):
There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
Any comment on that?
Regards,
Martin