CREATE PROCEDURE dbo.ReservationExternalRefCreate @AQualifier VARCHAR(100), @AExternalRef VARCHAR(8000), @AReferenceNumber INT, @AGuestNumber INT, @AUserIdNumber INT AS
SET NOCOUNT ON;
/*
  Created by Kent Johansen, October 2019
  Create a External Ref

  Remarks:
  There are no check for existing ExternalReference
*/

DECLARE @Ident INT

INSERT INTO ExternalReference (ParentID, Qualifier, Value) VALUES (NULL, 'ROOT', '')
SELECT @Ident = @@IDENTITY

INSERT INTO ReservationExternalRefXtab (FK_ReferenceNumber, FK_GuestNumber, FK_ExternalRefID, CreatedDatetime, UpdatedDatetime, FK_UserID) VALUES 
  (@AReferenceNumber, @AGuestNumber, @Ident, GETDATE(), GETDATE(), @AUserIdNumber)
INSERT INTO ExternalReference (ParentID, Qualifier, Value) VALUES (@Ident, 'HOTELRESID', '')
SELECT @Ident = @@IDENTITY

INSERT INTO ExternalReference (ParentID, Qualifier, Value) VALUES (@Ident, @AQualifier, @AExternalRef)