USE [LegitimateNational]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

Text                                                                                                                                                                                                                                                           
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                                                                                                                                                                                                                                                             
CREATE OR ALTER FUNCTION [App].[Fn_GetLicenceToUseFromSourceSystem]
                                                                                                                                                                                                 
(
                                                                                                                                                                                                                                                            
    @OlPermitNumber VARCHAR(100),
                                                                                                                                                                                                                            
    @SourceApplicationID SMALLINT = 3
                                                                                                                                                                                                                        
)
                                                                                                                                                                                                                                                            
-- SELECT App.Fn_GetLicenceToUseFromSourceSystem('LNPTR180200001/1', 3)  
                                                                                                                                                                                    
RETURNS XML
                                                                                                                                                                                                                                                  
AS
                                                                                                                                                                                                                                                           
BEGIN
                                                                                                                                                                                                                                                        
	DECLARE @OlPermitNumberWithVersionNumber VARCHAR(100) = @OlPermitNumber
                                                                                                                                                                                     
    DECLARE @SourceApplicationXML XML
                                                                                                                                                                                                                        
    DECLARE @IntegrationXML XML
                                                                                                                                                                                                                              
    DECLARE @QueryString VARCHAR(100)
                                                                                                                                                                                                                        
    DECLARE @ForcedRenewalPeriod INT
                                                                                                                                                                                                                         

                                                                                                                                                                                                                                                             
	SELECT @QueryString = 'olnumber=' + @OlPermitNumberWithVersionNumber
                                                                                                                                                                                        
	SELECT @IntegrationXML = Integration.GetData('GetVerifiedLicenceToUseXml', @QueryString)
                                                                                                                                                                    

                                                                                                                                                                                                                                                             
    RETURN @IntegrationXML
                                                                                                                                                                                                                                   
END
                                                                                                                                                                                                                                                          
