I am trying to perform a delete on a table that has 2 id’s with the differences of a view that I am using 2 ids on as well. Here is how I am finding the differences in Id’s:
Union of differences. Let’s say I have one table named Worker with columns WorkerId and ShiftId
Table1 data:
WorkerId ShiftId
5a5ae8d8-c2ca-4ae0-94d3-8d3a796e2c44 560697ee-42b8-4a95-b8f0-fd1f3f260c6a
4d3cffd0-a72f-475a-a5a9-b7131968f3c1 90fae4c4-55b3-4ba7-a8e3-c967da73f29c
44fa5e08-0219-4381-a904-f97fdcc69a3a 2e53e5fb-1fd1-4845-a930-f09d1cba5f69
3b55fbd8-06ec-4d6e-90a8-753d6b4d2411 e233dff6-8608-43be-89ed-13f935f5ef45
Then I have a sql view named v_Worker using the same Ids but with less records, so let’s say it looks like this:
WorkerId ShiftId
5a5ae8d8-c2ca-4ae0-94d3-8d3a796e2c44 560697ee-42b8-4a95-b8f0-fd1f3f260c6a
4d3cffd0-a72f-475a-a5a9-b7131968f3c1 90fae4c4-55b3-4ba7-a8e3-c967da73f29c
I am using this union to find the differences:
(SELECT WorkerId, ShiftId FROM dbo.Worker
EXCEPT
SELECT WorkerId, ShiftId FROM dbo.v_Worker)
UNION ALL
(SELECT WorkerId, ShiftId FROM dbo.v_Worker
EXCEPT
SELECT WorkerId, ShiftId FROM dbo.WorkerQueue)
This works fine and will return the differences of:
WorkerId ShiftId
44fa5e08-0219-4381-a904-f97fdcc69a3a 2e53e5fb-1fd1-4845-a930-f09d1cba5f69
3b55fbd8-06ec-4d6e-90a8-753d6b4d2411 e233dff6-8608-43be-89ed-13f935f5ef45
I have tried a few different things without much luck, mainly deleting all of my dataset instead of the differences. Any help would be appreciated, thanks.