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.
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