CREATE FUNCTION dbo.GetFolioCount(@ReferenceNumber INT, @GuestNumber INT)
RETURNS INT AS  
/*
   Created by Jacob Pedersen October 2005

   Parameters: @GuestNumber = -1 means check whole group
*/
BEGIN 
  DECLARE @FolioCount INT
  IF @GuestNumber = -1
    SELECT @FolioCount=COUNT(FolioNumber) FROM Folios WITH (NOLOCK) WHERE ReferenceNumber=@ReferenceNumber
  ELSE
    SELECT @FolioCount=COUNT(FolioNumber) FROM Folios WITH (NOLOCK) WHERE ReferenceNumber=@ReferenceNumber AND GuestNumber=@GuestNumber
  RETURN @FolioCount
END

