Home Dynamic delete statement based on join?
Reply: 0

Dynamic delete statement based on join?

user917 Published in June 19, 2018, 6:18 pm

I have a stored procedure with a GroupUserTVP table-valued parameter:

    [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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.255121 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO