CREATE PROCEDURE DBO.FindOrphentSubRes AS
SET NOCOUNT ON
/*
     Jacob 270202

     Last Update: 
*/
DECLARE @Referencenumber INT
DECLARE @thereferencenumber INT

DECLARE #AddressCur Cursor Forward_Only For

select distinct referencenumber from reservations WITH (nolock) where guestnumber > 0

  Open #AddressCur

  Fetch Next From #AddressCur
  Into @Referencenumber

  While  (@@FETCH_STATUS <> -1)
  Begin
    Select @TheReferencenumber = referencenumber from reservations WITH (nolock) where referencenumber=@referencenumber and guestnumber = 0
    if @@rowcount = 0
      print @referencenumber

    Fetch Next From #AddressCur
    Into @Referencenumber
  End

  Close #AddressCur
  Deallocate #AddressCur

