Created
          January 4, 2017 21:09 
        
      - 
      
 - 
        
Save aroder/02d5a3dceb97f35c0d3f9ad1fa4e4a87 to your computer and use it in GitHub Desktop.  
    Stored Procedure for Markit EDM Realign
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | if exists (select 1 from INFORMATION_SCHEMA.ROUTINES where ROUTINE_SCHEMA = 'dbo' and ROUTINE_NAME = 'spDmRealign') | |
| drop procedure dbo.spDmRealign | |
| go | |
| create procedure dbo.spDmRealign | |
| @oldCadisId int, | |
| @newCadisId int, /* Set @newCadisId = 0 below to get a *new* CadisID generated and assigned, or alternatively set to an existing target CadisID */ | |
| @matcherName nvarchar(100), | |
| @sourceName nvarchar(100) | |
| as begin | |
| declare @changedBy nvarchar(100) = current_user, | |
| @changedDate datetime = getdate(), | |
| @assignedCadisId int, | |
| @matcherId int, | |
| @sourceId int, | |
| @sql nvarchar(4000), | |
| @paramDefs nvarchar(500) | |
| select @matcherId = IDENTIFIER | |
| from CADIS_SYS.DM_MATCHPOINT | |
| where [NAME] = @matcherName | |
| and OBSOLETE = 0 | |
| if isnull(@matcherId, -99) = -99 | |
| begin | |
| print ('No active Matcher found with the name ' + @matcherName) | |
| return | |
| end | |
| print ('Processing matcher: ' + @matcherName) | |
| select @sourceId = SOURCEID | |
| from CADIS_SYS.DM_SOURCE | |
| where MATCHPOINTID = @matcherId | |
| and LONGNAME = @sourceName | |
| and OBSOLETE = 0 | |
| if isnull(@sourceId, -99) = -99 | |
| begin | |
| print ('No active Source found with name ' + @sourceName) | |
| return | |
| end | |
| print ('Processing Source: ' + @sourceName) | |
| set @sql = 'EXEC [CADIS_PROC].[SPDM_MP' + CONVERT(NVARCHAR, @matcherId) + '_SOURCE' + CONVERT(NVARCHAR, @sourceId) + '_REALIGN_MATCH] ' | |
| set @sql = @sql + '@OldCADISId, @NewCADISId, @ChangedBy, @ChangedDate, @assignedCadisId OUTPUT' | |
| set @paramDefs = '@oldCadisId INT, @newCadisId INT, @changedBy NVARCHAR(100), @changedDate DATETIME, @assignedCadisId INT OUTPUT' | |
| exec sp_executesql @sql, @paramDefs, @oldCadisId, @newCadisId, @changedBy, @changedDate, @assignedCADISId OUTPUT | |
| print ('Source realigned from CadisID ' + CONVERT(VARCHAR, @oldCadisId) + ' to CadisID ' + CONVERT(VARCHAR, @assignedCadisId)) | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment