I have a stored procedure with a GroupUserTVP table-valued parameter:
CREATE TYPE [dbo].[GroupUserTVP] AS TABLE
[GroupId] [uniqueidentifier] NULL,
[UserId] [uniqueidentifier] NULL
I have a
GroupUser table with the following structure:
CREATE TABLE [dbo].[GroupUser]
[GroupId] [uniqueidentifier] NOT NULL,
[UserId] [uniqueidentifier] NOT NULL
The TVP will contain a collection of GroupId's and UserId's. If the GroupUser table has group-users which don't exist in the TVP then those group-users should be deleted.
Is there a way to do some type of dynamic delete statement based on a join to accomplish this? I can break this into pieces and use table variables, etc but was wondering if there's a SQL expert here who could write this delete in a single statement or maybe 2 statements?