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

I am using above query to insert into table. I know @Table2 has multiple tWaveID and that's why it is showing error :

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

How to resolve that and insert twaveID repeating RequestID as 2222 for all entries?

2 Answers 2

7

Use the INSERT ... SELECT statement instead of a subquery:

INSERT INTO Reference_TB] ([RequestID] ,[WaveID]) 
(select 2222, tWaveID from @Table2)
Sign up to request clarification or add additional context in comments.

1 Comment

Great one! This did exactly what I wanted. However, in SQL Server, I get syntax error if I put the columnName FROM Table part at the head of the SELECT list. It has to be at the end. Do you know why that is?
4

Unsure of exact syntax as you didnt specify a system.

use a Insert select will insert all values

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

Comments

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.