Insert into a table with multiple values ​​in a subquery

INSERT INTO Reference_TB] ([RequestID] ,[WaveID]) VALUES (2222,(select tWaveID from @Table2)) 

I use the above query to insert into a table. I know that @Table2 has several tWaveID and therefore it shows an error:

A subquery returns more than 1 value. This is unacceptable when a subquery follows = ,! =, <, <=,>,> = or when the subquery is used as an expression.

How to resolve this and insert tWaveID repeating RequestID as 2222 for all records?

+4
source share
2 answers

Use INSERT ... SELECT instead of subquery:

 INSERT INTO Reference_TB] ([RequestID] ,[WaveID]) (select 2222, tWaveID from @Table2) 
+6
source

Not sure about the exact syntax since you did not specify a system.

use Insert Insert, paste all values

 INSERT INTO Reference_TB] ([RequestID] ,[WaveID]) select 2222,tWaveID from @Table2 
+4
source

Source: https://habr.com/ru/post/1447985/


All Articles