Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Sub query returns more than one value error

What is the issue with insert query below?

I’m trying to insert employee values from one table to another table. But the query gives an error:

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

DECLARE @EmployeeDetails AS [dbo].[Employee] 
 
INSERT INTO @EmployeeDetails
VALUES ( 101
       )
INSERT INTO @EmployeeDetails
VALUES ( 102
       )

INSERT INTO [dbo].[EmpCopy] (EmpId, Dept)) 
values (
(SELECT EmpId FROM @EmployeeDetails)
,'Sales')

>Solution :

You don’t have to specify the values if you want to insert all the data from another table

The correct syntax is:

INSERT INTO [dbo].[EmpCopy] (EmpId, Dept)
SELECT EmpId, 'Sales'
FROM @EmployeeDetails
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading