Hi
I need some help on a query. I need to delete some records from a table, this table has a dependency to another table
Table 1: dbo.Accounts and Table 2: dbo.AccountsToU ser
In the dbo.Accounts table there are
AccountId and OwnedByAccountI d
54708002 54708001
54708003 54708001
65708002 65708001
65708003 65708001
54708001 22334401
65708001 NULL
In the dbo.AccountsToU ser there are
AccountId and UserId
65708002 100
65708003 101
65708003 104
65708003 106
54708001 194
65708002 199
What I need is to delete every record from dbo.AccountsToU ser that has an account connection to an account in the dbo.Accounts that has OwnedByAccount like NULL
So in the example above I should delete from dbo.AccountsToU ser
65708002 100
65708003 101
65708003 104
65708003 106
Since they are connected to 65708001 which has OwnedByAccountS tatus like NULL
I could delete the records manually since the table isn’t that big, but I need this to be a daily job so all help would be very nice :)
Thanks!
I need some help on a query. I need to delete some records from a table, this table has a dependency to another table
Table 1: dbo.Accounts and Table 2: dbo.AccountsToU ser
In the dbo.Accounts table there are
AccountId and OwnedByAccountI d
54708002 54708001
54708003 54708001
65708002 65708001
65708003 65708001
54708001 22334401
65708001 NULL
In the dbo.AccountsToU ser there are
AccountId and UserId
65708002 100
65708003 101
65708003 104
65708003 106
54708001 194
65708002 199
What I need is to delete every record from dbo.AccountsToU ser that has an account connection to an account in the dbo.Accounts that has OwnedByAccount like NULL
So in the example above I should delete from dbo.AccountsToU ser
65708002 100
65708003 101
65708003 104
65708003 106
Since they are connected to 65708001 which has OwnedByAccountS tatus like NULL
I could delete the records manually since the table isn’t that big, but I need this to be a daily job so all help would be very nice :)
Thanks!
Comment