Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    2

    Unanswered: Multiple record outputs

    I have a table named Reservations that contains three fields. Room, From Date, To Date.

    If my fields were equal to:
    Room =A1 (Alpha Field)
    From Date =01/30/2004 (Date Field)
    To Date = 02/02/2004 (Date Field)

    I would like to output a record in the following format until the From Date field is greater than the To Date field. Table name=Booked

    Room A1
    Date 01/30/2004
    Month 01
    Day 30

    Now add 1 to the Date Field and output a record like

    Room A1
    Date 01/31/2004
    Month 01
    Day 31

    Add 1 to the Date Field and output Next record like

    Room A1
    Date 02/01/2004
    Month 02
    Day 01

    Add 1 to the Date Field and output Next record like

    Room A1
    Date 02/02/2004
    Month 02
    Day 02

    End of output records.

    Could you give me the coding for this? I assume it would be in a script.

    Thank you.

  2. #2
    Join Date
    Oct 2003
    Posts
    107
    You could do a scan loop. Assuming both tables already exist and the field names are as you described with Month and Day being integer (or number) fields.


    Code:
    var
    
       ResTC, BookTC    tCursor
       NxtDate            date
    
    endvar
    
    if not ResTC.open(":myAlias:Reservations.db") ; open Reservations
         then   errorShow()
                  return
    endif
    
    if not BookTC.open(":myAlias:Booking.db") ; Open Bookings 
         then   errorShow()
                  return
    endif
    
    BookTC.edit() ; put Booking.db in edit mode
    
    scan   ResTC:
    
         NxtDate = ResTC."From Date" ;assign start date
    
         while NxtDate <= ResTC."To Date" ; loop for bookings
    
              BookTC.insertAfterRecord() ; new record
              BookTC."Room" = ResTC."Room" ; transfer room number
              BookTC."Date" = NxtDate ; add date for this iteration
              BookTC."Month" = month(NxtDate) ; get the month
              BookTC."Day" = day(NxtDate)  ; get the day
              NxtDate = NxtDate+1 ; increment the date
    
         endWhile
    
    endscan
    
    ;close all tCursors
    BookTC.endEdit()
    BookTC.close()
    ResTC.close()
    I did this without a test and without my morning coffee. You may want to add some error trapping to catch records with blank To and/or From dates.

    Mac
    Last edited by lmckelvy; 08-20-04 at 11:09.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •