I just started working with SQL Server for the first time, and I had problems filling out test data. I have two tables that have a foreign key for the other, and I would like to be able to insert a new record using the following SQL:
insert into Employee (
EmployeeName,
DepartmentId
) values (
"John Doe",
(select Id from Department where DepartmentName = 'Accounting')
);
This statement works fine in Oracle, but in SQL Server I get an error:
Subqueries are not allowed in this context.
Does anyone know the correct way to do this in SQL Server?
source
share