SQL problem

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

kleel

Ars Scholae Palatinae
1,022
I'm stumped. the db schema involved looks like this...
4 tables as follows:

Hotels
------
ID
Name

|
|
8

HotelBooking
-------------
ID
HotelID

|
|
8

GuestLink
---------
ID
HotelBookingID
GUESTID

8
|
|

Guests
------
ID
FName
LName


I need to get a record set of all the bookings at a particular hotel.
which seems is straight forward enough until you realise that one or more guests can be sharing a booking (e.g. husband & wife) and I need to list them too (comma seperated)!


any ideas? my brain is hurting :confused:


K
 

kleel

Ars Scholae Palatinae
1,022
Originally posted by reboot:
select distinct bookings, ...
group by lname
I tried that ... which worked when I didnt include the guest names .. when I do the result is a new row for each guest which is not what I want as the report is going to be used as a check list for each hotel and needs to show each booking as upposed to each guest.
I'm not sure what you mean with the "|"s and "8"s
the "|"s and "8"s are "one to many" relationships - I didnt know how else to type them, sorry for the confusion.
 

kleel

Ars Scholae Palatinae
1,022
damn I thought that was going to be the case .. just was in denial I guess ...

Would putting the query to find each booking for a hotel into a cursor and looping thru adding the booking data & all the guests into a temp table and returning that work?

are cursors a bad idea?

This to be done in a Stored Procedure .. as I'm using crystal reports 8.5 for the reporting and I dont trust it's SQL builder, in fact I dont trust it at all :)
 

kleel

Ars Scholae Palatinae
1,022
ok I have it ! sorry if replying to your post is frowned apon .. I just need to share :D

The solution is a bit lengthy so I'll summerise.

one main booking_cursor, looping around all the bookings, for each booking a test to see if a booking is a sharing one or not is made.

If it is then another sharing_cursor is declared, opened and looped thru, concat'ing all the sharing guests names into a var. and deallocating the cursor.

If not then it just selects the guest involved into the same var as above.

The main cursor then selects all the values retrived and loops.

Nesting cursors like this scares me though the amount of times this will happen will be negliagable, plus the odds of more than 2 guests shareing is even rarer.
 
Status
You're currently viewing only kleel's posts. Click here to go back to viewing the entire thread.
Not open for further replies.