I have 2 tables.
- GeneralContractors
- Partners
Each GeneralContractor has its partners in partners table and each partner is associated to general contractor. Both table has IsBlackList against each record which means if I blackList a single general contractor in GC then all its partners will be blackListed too and when a partner is blacklisted then again for each partner it's general contractor would be blacklisted too and if that geenral contractor has it's own parnters then it will blacklist that partner too. So it's a recursive kinda situation going back and forth between partners and general contractors table. I have tried my best and achieved somehow but not completely. Please help me on it.
Code:
ALTER PROC [dbo].[UpdateContractorsBlackList]
@GContractorID varchar(20),
@BlackList bit
AS
BEGIN
Begin Try
Begin Transaction
Update GeneralContractors
set IsBlackList= @BlackList
Where GeneralContractorID= @GContractorID
Update Partners
Set IsBlackList= @BlackList
Where GeneralContractor_ID= @GContractorID
Commit Transaction
End Try
This the code I could and I did but I can't figure out what to do more.
GC table:
Partners table:
In a nutshell:
In a nutshell, If I blacklist a GC then it blacklists all associated partners and for each partner it checks it has associated record in GC table then it blacklists that too and then for each record in GC it blacklists the associated partners.
Update:
a bit of more code from partners perspective.
Update Partners
Set IsBlackList= @BlackList
Where CNIC= @CNIC
Update gc
Set gc.IsBlackList= @BlackList
From GeneralContractors gc
Inner Join Partners p
ON p.GeneralContractor_ID= gc.GeneralContractorID
Where p.CNIC= @CNIC