-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #413 from SkillsFundingAgency/DPP-1671_Data_fix_mi…
…ssing_relationship Adds script to create relationship
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/SFA.DAS.Commitments.Database/AdhocScripts/Support/RelationshipCreationScript.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Relationship creation script | ||
The purpose of this script is to create a Employer-Provider Relationship record in commitments. Under normal circumstances, | ||
a Relationship is created when the Employer first sends a Provider a Cohort. When this Relationship is not created due to | ||
technical issues at the time (at time of writing, the two operations are not atomic), when the Provider goes to view the cohort | ||
and exception is thrown and the only known work-around is to have the Employer send another, empty cohort, to their Provider. | ||
*/ | ||
|
||
declare @ProviderId bigint = 0; -- Set the UKPRN of the provider for whom to create the relationship | ||
declare @EmployerAccountId bigint = 0; -- Set the AccountId of the employer for whom to create the relationship | ||
declare @LegalEntityCode nvarchar(50) = ''; --Set the Code of the legal entity for whom to create the relationship | ||
|
||
|
||
|
||
/* | ||
************* MODIFY BELOW THIS LINE AT YOUR PERIL ******************* | ||
*/ | ||
|
||
insert into [dbo].[Relationship] | ||
select | ||
top 1 | ||
c.ProviderId, | ||
c.ProviderName, | ||
c.EmployerAccountId, | ||
c.LegalEntityId, | ||
c.LegalEntityName, | ||
c.LegalEntityAddress, | ||
c.LegalEntityOrganisationType, | ||
null as Verified, | ||
GETDATE() as CreatedOn | ||
from | ||
[dbo].[Commitment] c | ||
where c.ProviderId = @ProviderId and c.EmployerAccountId = @EmployerAccountId and c.LegalEntityId = @LegalEntityCode | ||
and not exists (select 1 from Relationship where ProviderId = @ProviderId and EmployerAccountId = @EmployerAccountId and LegalEntityId = @LegalEntityCode) | ||
order by c.Id desc | ||
|
||
|
||
if(@@ROWCOUNT=0) | ||
begin | ||
print 'Error - Relationship already exists, or no Commitment found' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters