I have two tables in two separate databases. I'm trying to take all of the employee IDs that were inserted into the employee database yesterday and input them into our purchasing database with an additional column containing a role within our purchasing platform.
DECLARE @today date = GETDATE();
INSERT INTO dbo.PurchasingDB(UserId, RoleId)
VALUES
((SELECT EMPLOYEE_ID FROM
Employee.dbo.EMPLOYEE_INFO
WHERE DATE_LOADED >= DATEADD(DAY, -1, @today)
AND DATE_LOADED < @today)
,'REQUESTOR');
The problem that I'm having is that I receive the following error when I run the statement above:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
I guess there are a few questions here:
- Is there a simpler way to retrieve the rows that were entered into the employee database yesterday?
- What, if any, are the alternatives to using the >= and < operators when trying to do a comparison, or in this case, retrieve yesterdays date.
- Am I going about this the wrong way? Would it make sense to do separate SQL statements?