SQL problem

Status
You're currently viewing only bigterp's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

bigterp

Ars Tribunus Militum
1,576
So for the query it looks like there's a one to many relationship between Hotel Bookings and Guests, meaning each hotel booking can have one or more guests. What happens if there's more than two guests for a booking?

EDIT:
You really can't produce a comma delimited list from a single SQL query when you don't know how many names can be related to a booking. That's more of a report program task.

EDIT:

However you can produce a list of names for each Bookings by grouping by Hotel and Bookings.

Select h.name, b.id, g.Fname, g,Lname
from hotel h, Hotelbooking b, guests g, GuestLink as GL,
where h.id = b.hotelid
and b.id = gl.hotelbookingid
and gl.guestid = g.id
group by h.name, b.id

[This message was edited by bigterp on February 05, 2002 at 11:24.]
 

bigterp

Ars Tribunus Militum
1,576
Actually it would be easier if you always got the customer cursor:

For a booking open the cursor
If the cursor has data
Write the names of the first customer
advance the cursor
while the cursor still has customers
Write a comma
Write the current customer names
advance the cursor
end while
end if
close cursor

Thereby avoiding multiple selects, and the corresponding maintenace overhead.
 
Status
You're currently viewing only bigterp's posts. Click here to go back to viewing the entire thread.
Not open for further replies.