SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CreateReservationFollowup]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CreateReservationFollowup]
GO

CREATE PROCEDURE DBO.CreateReservationFollowup @AReferenceNumber INT, @AGuestNumber INT, @AUserIdNumber INT, @AFollowupText VARCHAR(8000), @AHotelNumber INT AS
SET NOCOUNT ON

/*
  Created by: Kent Johansen october 2007
  Create a new followup on a reservation

*/

DECLARE @SystemDateTime DATETIME
DECLARE @SystemDateStr CHAR(8)
DECLARE @NewFollowUpNumber INT

SELECT  @SystemDateStr = SystemDate FROM System WITH (NOLOCK) WHERE Number = 1
SELECT @SystemDateTime = CONVERT(DATETIME, @SystemDateStr, 112) + CONVERT (CHAR, GetDate(), 108)

INSERT INTO FollowUp ([Date], Type, Priority, State, Note, CreatedDate, CreatedBy, SubType, HotelNumber)
VALUES (@SystemDateTime, 5, 12, 3, @AFollowupText, @SystemDateTime, @AUserIdNumber, 1, @AHotelNumber)
SELECT @NewFollowUpNumber = @@identity
INSERT INTO ReservationFollowUpXTab (ReferenceNumber, GuestNumber, FollowUpNumber) VALUES (@AReferenceNumber, @AGuestNumber, @NewFollowUpNumber)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

