CREATE FUNCTION [dbo].[GetReservationCreateDate] (@AReferenceNumber INT, @AGuestNumber INT)

/*
  Created december 2008 by Kent Johansen  
  Changes:

*/

RETURNS DATETIME
AS
BEGIN
  DECLARE @Return DATETIME
  SELECT @Return = CreatedDate FROM ReservationFollowUpXTab WITH (NOLOCK) 
  INNER JOIN FollowUp WITH (NOLOCK) ON ReservationFollowUpXTab.FollowUpNumber=FollowUp.FollowUpNumber
    AND ReferenceNumber=@AReferenceNumber 
    AND GuestNumber=@AGuestNumber 
    AND Type=5 
    AND Note LIKE 'Created%'

 RETURN @return
END