/* vd20190521 New way of searching customer - Inner procedure */

CREATE PROCEDURE [dbo].[CustomerSearchResult]
  @IncludeDeleted BIT,
  @IncludeLinkRecords BIT,
  @ExcludeSalesChannels BIT,     
  @SwitchNameOrder BIT,
  @RoomNumber INTEGER,
  @CustomerType SMALLINT, 
  @CustomerNumber INTEGER,
  @FirstName VARCHAR(50),
  @LastName VARCHAR(60),
  @Phone VARCHAR(30),
  @Mobile VARCHAR(30),
  @MemberCard VARCHAR(128),
  @MemberCardEncrypted VARCHAR(128),
  @IATANumber VARCHAR(30),
  @CompanyNumber VARCHAR(30),
  @DebtorAccount VARCHAR(20),
  @MailAddress VARCHAR(100),
  @EAN VARCHAR(20),
  @CardString VARCHAR(255),
  @Criteria NVARCHAR(MAX)
AS

DECLARE @BASE_SELECT NVARCHAR(MAX)
DECLARE @BASE_WHERE NVARCHAR(MAX)

DECLARE @myFullName VARCHAR(110)
DECLARE @myLink INTEGER
DECLARE @myLinkLevel TINYINT
DECLARE @myCustomerNumber INTEGER
DECLARE @myCustomerTypeNumber SMALLINT
DECLARE @myMarkAsDeleted BIT
DECLARE @myNBDate VARCHAR(8)
DECLARE @myTitle VARCHAR(100)
DECLARE @myFirstName VARCHAR(50)
DECLARE @myLastName VARCHAR(60)
DECLARE @myAddress1 VARCHAR(100)
DECLARE @myAddress2 VARCHAR(100)
DECLARE @myAddress3 VARCHAR(100)
DECLARE @myZipCodeOverWrite VARCHAR(10)
DECLARE @myCityOverWrite VARCHAR(50)
DECLARE @myCountryNumber INTEGER
DECLARE @myPhoneNumber VARCHAR(30)
DECLARE @myCellPhoneNumber VARCHAR(30)
DECLARE @myFaxNumber VARCHAR(30)
DECLARE @myWWWAddress VARCHAR(100)
DECLARE @myCompanyNumber VARCHAR(30)
DECLARE @myIATANumber VARCHAR(30)
DECLARE @myMemberCardNumber VARCHAR(128)
DECLARE @myExternDebitorNumber INTEGER
DECLARE @myFlagA VARCHAR(300)
DECLARE @myFlagB VARCHAR(300)
DECLARE @myFlagC VARCHAR(300)
DECLARE @myFlagD VARCHAR(300)
DECLARE @myMappedCustomerNumber INTEGER
DECLARE @myDebtorAccount VARCHAR(20)
DECLARE @myDepersonalised BIT
DECLARE @myMailAddress VARCHAR(100)
DECLARE @myEAN VARCHAR(20)
DECLARE @myNote1 NVARCHAR
DECLARE @myNote2 NVARCHAR
DECLARE @myNote3 NVARCHAR 
DECLARE @myGDPRMail SMALLDATETIME 
DECLARE @myUserIDCode VARCHAR(20)
DECLARE @mySegment VARCHAR(30)
DECLARE @myGuestType VARCHAR(50)
DECLARE @myPurpose VARCHAR(50)
DECLARE @myPOS VARCHAR(30)
DECLARE @myCountryCode VARCHAR(3)
DECLARE @myCountryName VARCHAR(30)
DECLARE @mySplitBill VARCHAR(20)
DECLARE @myPayment VARCHAR(50)
DECLARE @myRoomNumber INTEGER 
DECLARE @myInetLogin VARCHAR(50)
DECLARE @myInetPassword VARCHAR(50)
DECLARE @myCardString VARCHAR(255)
DECLARE @myGDPRAction DATETIME

SET @BASE_SELECT = 'DECLARE #HeadCursor CURSOR FAST_FORWARD FOR 
  SELECT     
    CASE WHEN C.FirstName <> '''' THEN CASE WHEN ' + CAST(@SwitchNameOrder AS CHAR) + ' = 1 THEN 
	C.LastName + '' '' + C.FirstName ELSE C.FirstName + '' '' + C.LastName	END ELSE C.LastName END AS FullName,
    C.CustomerNumber Link, 0 LinkLevel, C.CustomerNumber, C.CustomerTypeNumber, C.MarkAsDeleted, C.NBDate, C.Title, 
    C.FirstName, C.LastName, C.Address1, C.Address2, C.Address3, C.ZipCodeOverWrite, C.CityOverWrite, 
    C.CountryNumber, C.PhoneNumber, C.CellPhoneNumber, C.FaxNumber, C.WWWAddress, C.CompanyNumber,
    C.IATANumber, C.MemberCardNumber, C.ExternDebitorNumber, C.FlagA, C.FlagB, C.FlagC, C.FlagD, 
    C.MappedCustomerNumber, C.DebtorAccount, CAST (ISNULL(C.CustomerAnonymized, 0) AS BIT) Depersonalised, 
    MailAddresses.MailAddress, E1.EAN, n1.Contents AS Note1, n2.Contents AS Note2, n3.Contents AS Note3,
   (SELECT MAX(GDPRMailDate) FROM GDPRMail WITH (NOLOCK) WHERE GDPRMail.CustomerNumber = C.CustomerNumber) AS GDPRMail,
    P.UserIDCode, Segments.Text AS Segments1, GuestTypes.Text AS GuestTypes1, PurposeCodes.Text AS Purpose, PointOfSales.Text AS PointOfSale,
    Countries.CountryCode, Countries.CountryName, SplitBill.Name SplitBill, Ware.WareName Payment,
    CASE WHEN ' + CAST(@RoomNumber AS CHAR) + ' = 0 THEN (SELECT TOP 1 R.NUMBER FROM ROOMS R (NOLOCK) WHERE R.CustomerNumber = C.CustomerNumber)
      ELSE ''' + CAST (@RoomNumber AS VARCHAR) + ''' END OwnerRoomNumber,
    InetCustomer.CustomerLogin InetLogin, InetCustomer.CustomerPassword InetPassword,      
   (SELECT MIN(CD.CardString) FROM CARD CD (NOLOCK) JOIN CustomerCardXTab CCX WITH(NOLOCK) ON 
      CCX.CustomerNumber = C.CustomerNumber AND CCX.FK_Card = CD.PK_Card AND ISNULL(CCX.LogNumberDelete, 0) = 0 
        JOIN CardTypeXTab CTX WITH(NOLOCK) ON CTX.FK_Card = CD.PK_Card 
        JOIN CardType CT WITH(NOLOCK) ON CT.PK_CardType = CTX.FK_CardType AND CT.Type IN (2, 12, 14)) AS CardString, 
   (SELECT CASE WHEN 
      ISNULL((SELECT MAX(X.DateApprove) 
              FROM GDPRApproveCustomerXTab X WITH (NOLOCK) 
              WHERE X.FK_CustomerNumber = C.CustomerNumber), 0) > 
      ISNULL((SELECT MAX(X.DateReject) 
              FROM GDPRApproveCustomerXTab X WITH (NOLOCK) 
              WHERE X.FK_CustomerNumber = C.CustomerNumber), 0) THEN 
   (SELECT MAX(X.DateApprove) 
      FROM GDPRApproveCustomerXTab X WITH (NOLOCK) 
      WHERE X.FK_CustomerNumber = C.CustomerNumber) ELSE 
   (SELECT MAX(X.DateReject) 
      FROM GDPRApproveCustomerXTab X WITH (NOLOCK) 
      WHERE X.FK_CustomerNumber = C.CustomerNumber) END) GDPRAction    
  FROM Customer C WITH (NOLOCK) 
    LEFT JOIN MailAddresses WITH (NOLOCK) ON MailAddresses.CustomerNumber = C.CustomerNumber AND MailAddresses.MailAddressType = 0 
    LEFT JOIN CustomerEANS E1 WITH (NOLOCK) ON E1.CustomerNumber = C.CustomerNumber 
    LEFT JOIN NoteContents N1  WITH (NOLOCK) ON N1.PageNumber = 1 AND N1.CustomerNumber = C.CustomerNumber 
    LEFT JOIN NoteContents N2  WITH (NOLOCK) ON N2.PageNumber = 2 AND N2.CustomerNumber = C.CustomerNumber  
    LEFT JOIN NoteContents N3  WITH (NOLOCK) ON N3.PageNumber = 3 AND N3.CustomerNumber = C.CustomerNumber 
    LEFT JOIN Personel P WITH (NOLOCK) ON C.SalesmanNumber = P.UserIdNumber AND IsNull(P.MarkAsDeleted, 0) = 0 
    LEFT JOIN Segments WITH (NOLOCK) ON Segments.Number = C.SegmentNumber 
    LEFT JOIN GuestTypes WITH (NOLOCK) ON GuestTypes.TypeNumber = C.GuestTypeNumber 
    LEFT JOIN PurposeCodes WITH (NOLOCK) ON PurposeCodes.PurposeCodeNumber = C.PurposeCodeNumber 
    LEFT JOIN PointOfSales WITH (NOLOCK) ON PointOfSales.Number = C.PointOfSaleNumber
    LEFT JOIN Countries WITH (NOLOCK) ON Countries.CountryNumber = C.CountryNumber  
    LEFT JOIN SplitBill WITH (NOLOCK) ON SplitBill.SplitBillNumber = C.SplitBillNumber 
    LEFT JOIN Ware WITH (NOLOCK) ON Ware.WareNumber = C.PaymentTypeWareNumber
    LEFT JOIN InetCustomer WITH (NOLOCK) ON InetCustomer.CustomerNumber = C.CustomerNumber '

IF @CardString <> ''
  SET @BASE_SELECT = @BASE_SELECT + 
  '  JOIN CustomerCardXTab CCX WITH (NOLOCK) ON CCX.CustomerNumber = C.CustomerNumber AND ISNULL(CCX.LogNumberDelete, 0) = 0
	 JOIN Card CD WITH (NOLOCK) ON CCX.FK_Card = CD.PK_Card AND CD.CardString LIKE ''%' + @CardString + '%''
     JOIN CardTypeXTab CTX WITH (NOLOCK) ON CTX.FK_Card = CD.PK_Card	  
     JOIN CardType CT WITH (NOLOCK) ON CT.PK_CardType = CTX.FK_CardType '

SET @BASE_WHERE =
  'WHERE ISNULL(C.MarkAsDeleted, 0) < 1 + ' + CAST(@IncludeDeleted AS CHAR)

IF @ExcludeSalesChannels = 1
  SET @BASE_WHERE = @BASE_WHERE + '  AND C.CustomerTypeNumber <> 7 '

IF @CustomerType IN (1, 2, 3, 4, 5, 6, 7, 8)
  SET @BASE_WHERE = @BASE_WHERE + '  AND C.CustomerTypeNumber = ' + CAST (@CustomerType AS CHAR) + ' '

IF @RoomNumber > 0
  SET @BASE_WHERE = @BASE_WHERE + '  AND EXISTS (SELECT 1 FROM ROOMS R WHERE R.NUMBER > ''' + 
    CAST (@RoomNumber AS VARCHAR) + ''' AND R.CustomerNumber = C.CustomerNumber) '

IF @CustomerNumber > 0
  SET @BASE_WHERE = @BASE_WHERE + '  AND C.CustomerNumber LIKE ''' + CAST (@CustomerNumber AS VARCHAR) + '%'''

IF @FirstName <> ''
  SET @BASE_WHERE = @BASE_WHERE + '  AND C.FirstName LIKE ''' + @FirstName + '%'''

IF @LastName <> ''
  SET @BASE_WHERE = @BASE_WHERE + '  AND C.LastName LIKE ''' + @LastName + '%'''

IF @Phone <> ''
  SET @BASE_WHERE = @BASE_WHERE + '  AND (REPLACE(C.PhoneNumber, '' '', '''') LIKE ''' + REPLACE(@Phone, ' ', '') + '%''' + 
         ' OR REPLACE(C.CellPhoneNumber, '' '', '''') LIKE ''' + REPLACE(@Phone, ' ', '') + '%'')' 
  
IF @Mobile <> ''
  SET @BASE_WHERE = @BASE_WHERE + '  AND (REPLACE(C.PhoneNumber, '' '', '''') LIKE ''' + REPLACE(@Mobile, ' ', '') + '%''' + 
         ' OR REPLACE(C.CellPhoneNumber, '' '', '''') LIKE ''' + REPLACE(@Mobile, ' ', '') + '%'')'  

IF @MemberCard <> ''
  SET @BASE_WHERE = @BASE_WHERE + '  AND (REPLACE(C.MemberCardNumber, '' '', '''') LIKE ''' + REPLACE(@MemberCard, ' ', '') + '%''' + 
   ' OR REPLACE(C.MemberCardNumber, '' '', '''') LIKE ''' + REPLACE(@MemberCardEncrypted, ' ', '') + '%'')' 

IF @IATANumber <> ''
  SET @BASE_WHERE = @BASE_WHERE + '  AND REPLACE(C.IATANumber, '' '', '''') LIKE ''' + REPLACE(@IATANumber, ' ', '') + '%'''

IF @CompanyNumber <> ''
  SET @BASE_WHERE = @BASE_WHERE + '  AND REPLACE(C.CompanyNumber, '' '', '''') LIKE ''' + REPLACE(@CompanyNumber, ' ', '') + '%'''

IF @DebtorAccount <> ''
  SET @BASE_WHERE = @BASE_WHERE + '  AND (REPLACE(C.DebtorAccount, '' '', '''') LIKE ''' + REPLACE(@DebtorAccount, ' ', '') + '%''' + 
   ' OR REPLACE(C.ExternDebitorNumber, '' '', '''') LIKE ''' + REPLACE(@DebtorAccount, ' ', '') + '%'')' 

IF @MailAddress <> ''
  SET @BASE_WHERE = @BASE_WHERE + '  AND MailAddresses.MailAddress LIKE ''' + @MailAddress + '%'''

IF @EAN <> ''
  SET @BASE_WHERE = @BASE_WHERE + '  AND E1.EAN LIKE ''' + @EAN + '%''' +
  '  AND E1.EANTYPE = (SELECT MIN (EANTYPE) FROM CustomerEANS E2 WITH (NOLOCK) WHERE E2.CustomerNumber = C.CustomerNumber AND E2.EAN LIKE ''' + @EAN + '%'')'
ELSE
  SET @BASE_WHERE = @BASE_WHERE + '  AND ISNULL(E1.EANTYPE, 0) = 0 '

IF @Criteria <> ''
  SET @BASE_WHERE = @BASE_WHERE + ' AND (' + @Criteria + ') '

EXEC (@BASE_SELECT + @BASE_WHERE)	
OPEN #HeadCursor

FETCH NEXT FROM #HeadCursor
INTO 
  @myFullName,
  @myLink,
  @myLinkLevel,
  @myCustomerNumber, 
  @myCustomerTypeNumber,
  @myMarkAsDeleted,
  @myNBDate,
  @myTitle,
  @myFirstName, 
  @myLastName, 
  @myAddress1, 
  @myAddress2, 
  @myAddress3,
  @myZipCodeOverWrite,
  @myCityOverWrite,
  @myCountryNumber, 
  @myPhoneNumber,
  @myCellPhoneNumber,
  @myFaxNumber,
  @myWWWAddress,
  @myCompanyNumber,
  @myIATANumber,
  @myMemberCardNumber,
  @myExternDebitorNumber, 
  @myFlagA,
  @myFlagB,
  @myFlagC,
  @myFlagD,
  @myMappedCustomerNumber,
  @myDebtorAccount,
  @myDepersonalised,
  @myMailAddress,
  @myEAN,
  @myNote1,
  @myNote2,
  @myNote3,
  @myGDPRMail,
  @myUserIDCode,
  @mySegment,
  @myGuestType,
  @myPurpose,
  @myPOS,
  @myCountryCode,
  @myCountryName,
  @mySplitBill,
  @myPayment,
  @myRoomNumber,
  @myInetLogin,
  @myInetPassword,  
  @myCardString,
  @myGDPRAction;
  
WHILE @@FETCH_STATUS = 0 
BEGIN

  INSERT INTO #RESULTSET VALUES (
  @myFullName,
  @myLink,
  @myLinkLevel,
  @myCustomerNumber, 
  @myCustomerTypeNumber,
  @myMarkAsDeleted,
  @myNBDate,
  @myTitle,
  @myFirstName, 
  @myLastName, 
  @myAddress1, 
  @myAddress2, 
  @myAddress3,
  @myZipCodeOverWrite,
  @myCityOverWrite,
  @myCountryNumber, 
  @myPhoneNumber,
  @myCellPhoneNumber,
  @myFaxNumber,
  @myWWWAddress,
  @myCompanyNumber,
  @myIATANumber,
  @myMemberCardNumber,
  @myExternDebitorNumber, 
  @myFlagA,
  @myFlagB,
  @myFlagC,
  @myFlagD,
  @myMappedCustomerNumber,
  @myDebtorAccount,
  @myDepersonalised,
  @myMailAddress,
  @myEAN,
  @myNote1,
  @myNote2,
  @myNote3,
  @myGDPRMail,
  @myUserIDCode,
  @mySegment,
  @myGuestType,
  @myPurpose,
  @myPOS,
  @myCountryCode,
  @myCountryName,
  @mySplitBill,
  @myPayment,
  @myRoomNumber,
  @myInetLogin,
  @myInetPassword,  
  @myCardString,
  @myGDPRAction
  );


  IF @IncludeLinkRecords = 1
    INSERT INTO #RESULTSET
    SELECT 
      CASE WHEN C.FirstName <> '' THEN CASE WHEN @SwitchNameOrder = 1 THEN C.LastName + ' ' + C.FirstName ELSE C.FirstName + ' ' + C.LastName END ELSE C.LastName END AS FullName,
      @myCustomerNumber Link, 1 LinkLevel, C.CustomerNumber, C.CustomerTypeNumber, C.MarkAsDeleted, C.NBDate, 
      C.Title, C.FirstName, C.LastName, C.Address1, C.Address2, C.Address3, 
      C.ZipCodeOverWrite, C.CityOverWrite, C.CountryNumber, 
      C.PhoneNumber, C.CellPhoneNumber, C.FaxNumber, C.WWWAddress,
      C.CompanyNumber, C.IATANumber, C.MemberCardNumber, C.ExternDebitorNumber, 
      C.FlagA, C.FlagB, C.FlagC, C.FlagD, 
      C.MappedCustomerNumber, C.DebtorAccount, CAST (ISNULL(C.CustomerAnonymized, 0) AS BIT) Depersonalised, 
      MailAddresses.MailAddress, E1.EAN, n1.Contents AS Note1, n2.Contents AS Note2, n3.Contents AS Note3,
     (SELECT MAX(GDPRMailDate) FROM GDPRMail WITH (NOLOCK) WHERE GDPRMail.CustomerNumber = C.CustomerNumber) AS GDPRMail,
      P.UserIDCode, Segments.Text AS Segments1, GuestTypes.Text AS GuestTypes1, PurposeCodes.Text AS Purpose, PointOfSales.Text AS PointOfSale, 
      Countries.CountryCode, Countries.CountryName, SplitBill.Name SplitBill, Ware.WareName Payment,
      CASE WHEN @RoomNumber = 0 THEN (SELECT TOP 1 R.NUMBER FROM ROOMS R (NOLOCK) WHERE R.CustomerNumber = C.CustomerNumber) ELSE @RoomNumber END OwnerRoomNumber,
      InetCustomer.CustomerLogin InetLogin, InetCustomer.CustomerPassword InetPassword,	 
     (SELECT MIN(CD.CardString) FROM CARD CD (NOLOCK) JOIN CustomerCardXTab CCX WITH(NOLOCK) ON 
        CCX.CustomerNumber = C.CustomerNumber AND CCX.FK_Card = CD.PK_Card AND ISNULL(CCX.LogNumberDelete, 0) = 0 
          JOIN CardTypeXTab CTX WITH(NOLOCK) ON CTX.FK_Card = CD.PK_Card 
          JOIN CardType CT WITH(NOLOCK) ON CT.PK_CardType = CTX.FK_CardType AND CT.Type IN (2, 12, 14)) AS CardString, 
     (SELECT CASE WHEN 
        ISNULL((SELECT MAX(X.DateApprove) 
                FROM GDPRApproveCustomerXTab X WITH (NOLOCK) 
                WHERE X.FK_CustomerNumber = C.CustomerNumber), 0) > 
        ISNULL((SELECT MAX(X.DateReject) 
                FROM GDPRApproveCustomerXTab X WITH (NOLOCK) 
                WHERE X.FK_CustomerNumber = C.CustomerNumber), 0) THEN 
     (SELECT MAX(X.DateApprove) 
      FROM GDPRApproveCustomerXTab X WITH (NOLOCK) 
      WHERE X.FK_CustomerNumber = C.CustomerNumber) ELSE 
     (SELECT MAX(X.DateReject) 
      FROM GDPRApproveCustomerXTab X WITH (NOLOCK) 
      WHERE X.FK_CustomerNumber = C.CustomerNumber) END) GDPRAction   	     
    FROM Customer C WITH (NOLOCK) 
      LEFT JOIN MailAddresses WITH (NOLOCK) ON MailAddresses.CustomerNumber = C.CustomerNumber AND MailAddresses.MailAddressType = 0 
      LEFT JOIN CustomerEANS E1 WITH (NOLOCK) ON E1.CustomerNumber = C.CustomerNumber AND E1.EANTYPE = 0 
      LEFT JOIN NoteContents N1  WITH (NOLOCK) ON N1.PageNumber = 1 AND N1.CustomerNumber = C.CustomerNumber 
      LEFT JOIN NoteContents N2  WITH (NOLOCK) ON N2.PageNumber = 2 AND N2.CustomerNumber = C.CustomerNumber  
      LEFT JOIN NoteContents N3  WITH (NOLOCK) ON N3.PageNumber = 3 AND N3.CustomerNumber = C.CustomerNumber 
      LEFT JOIN Personel P WITH (NOLOCK) ON C.SalesmanNumber = P.UserIdNumber AND IsNull(P.MarkAsDeleted, 0) = 0  
      LEFT JOIN Segments WITH (NOLOCK) ON Segments.Number = C.SegmentNumber   
      LEFT JOIN GuestTypes WITH (NOLOCK) ON GuestTypes.TypeNumber = C.GuestTypeNumber 
      LEFT JOIN PurposeCodes WITH (NOLOCK) ON PurposeCodes.PurposeCodeNumber = C.PurposeCodeNumber 
      LEFT JOIN PointOfSales WITH (NOLOCK) ON PointOfSales.Number = C.PointOfSaleNumber 
      LEFT JOIN Countries WITH (NOLOCK) ON Countries.CountryNumber = C.CountryNumber 
      LEFT JOIN SplitBill WITH (NOLOCK) ON SplitBill.SplitBillNumber = C.SplitBillNumber
      LEFT JOIN Ware WITH (NOLOCK) ON Ware.WareNumber = C.PaymentTypeWareNumber
      LEFT JOIN InetCustomer WITH (NOLOCK) ON InetCustomer.CustomerNumber = C.CustomerNumber
    WHERE ISNULL(C.MarkAsDeleted, 0) < 1 + @IncludeDeleted AND
	(
    C.CUSTOMERNUMBER IN (SELECT CUSTOMERNUMBER FROM CUSTOMERLINKS CL (NOLOCK)
                         WHERE CL.CUSTOMERLINKNUMBER = CAST (@myCustomerNumber AS CHAR)) OR 
    C.CUSTOMERNUMBER IN (SELECT CUSTOMERLINKNUMBER FROM CUSTOMERLINKS CL (NOLOCK)
                         WHERE CL.CUSTOMERNUMBER = CAST (@myCustomerNumber AS CHAR))
    )

FETCH NEXT FROM #HeadCursor
INTO 
  @myFullName,
  @myLink,
  @myLinkLevel,
  @myCustomerNumber, 
  @myCustomerTypeNumber,
  @myMarkAsDeleted,
  @myNBDate,
  @myTitle,
  @myFirstName, 
  @myLastName, 
  @myAddress1, 
  @myAddress2, 
  @myAddress3,
  @myZipCodeOverWrite,
  @myCityOverWrite,
  @myCountryNumber, 
  @myPhoneNumber,
  @myCellPhoneNumber,
  @myFaxNumber,
  @myWWWAddress,
  @myCompanyNumber,
  @myIATANumber,
  @myMemberCardNumber,
  @myExternDebitorNumber, 
  @myFlagA,
  @myFlagB,
  @myFlagC,
  @myFlagD,
  @myMappedCustomerNumber,
  @myDebtorAccount,
  @myDepersonalised,
  @myMailAddress,
  @myEAN,
  @myNote1,
  @myNote2,
  @myNote3,
  @myGDPRMail,
  @myUserIDCode,
  @mySegment,
  @myGuestType,
  @myPurpose,
  @myPOS,
  @myCountryCode,
  @myCountryName,
  @mySplitBill,
  @myPayment,
  @myRoomNumber,
  @myInetLogin,
  @myInetPassword,  
  @myCardString,
  @myGDPRAction;
  
END

CLOSE #HeadCursor 
DEALLOCATE #HeadCursor
GO
