CREATE FUNCTION dbo.getroomnumber  (@ref int, @guest int)
RETURNS int
AS
BEGIN
 declare @return int
 select distinct @return = max(note) from transactions WITH (nolock) where folionumber in (select FolioNumber from folios WITH (nolock) where referencenumber = @ref AND GUESTNUMBER = @GUEST)
 return @return
end

