If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Booking database - query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-02, 11:47
coolblue coolblue is offline
Registered User
 
Join Date: Jul 2002
Location: UK
Posts: 4
Post Booking database - query

Hi,

I need to write a qry for sql 7/ASP to select a 72hr X 5 matrix of 1/2 hr periods - values need to show booked/unbooked for each of 5 cars for all 72 hours. The problem is the database only stores records for the booked periods.

The query (below) works ok for 1 car & one time slot, but calling this 720 times is not good! - Ideally I need some query that can return all the data in one go, and use the recordset to build a table showing availablity.

How do I write this kind of query ?

Thanks
---------

dteDateTime="27-Jul-02 15:30"
iCarID=3

SELECT [pk_bookedTimeID] FROM tblBookedTimes INNER JOIN tblBookings ON [tblBookedTimes].[fk_bookingID]=[tblBookings].[pk_bookingID] WHERE [tblBookings].[fk_carID]=" & iCarID & " AND " & "[tblBookedTimes].[bookedTime] = '" & dteDateTime & "'"
Reply With Quote
  #2 (permalink)  
Old 07-24-02, 10:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
can you give a brief example of what the result set is supposed to look like with the holes in it?

have a look at Finding all the dates between two dates which shows how to use an integer table to generate dates

rudy
http://rudy.ca/
Reply With Quote
  #3 (permalink)  
Old 07-24-02, 11:01
coolblue coolblue is offline
Registered User
 
Join Date: Jul 2002
Location: UK
Posts: 4
Hi,

The results would be as follows :

car_id | 24/07/02 00:00 | 24/07/02 00:30 | 24/07/02 01:00 ...
1 0 1 1
2 1 1 1
3 1 1 1

Each row would be a car, each column a date/time.
The date/times would cover 72 hrs ( 144 columns)
from any date/time specified.

The problem I have is that I only store the 1's in the db not the 0's!

The article looks like exactly what Im trying to do - Thanks.
Reply With Quote
  #4 (permalink)  
Old 07-24-02, 11:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
okay, what you want is a cross-tab report, and since you'll have to do that in asp anyway, there's not much point generating the missing values with sql, just do them with asp too...

rudy
Reply With Quote
  #5 (permalink)  
Old 07-24-02, 11:20
coolblue coolblue is offline
Registered User
 
Join Date: Jul 2002
Location: UK
Posts: 4
Thanks rudy,

At least I know what its called now! that was half the problem trying to research it.

I have solved this already in ASP, the performance was so bad- thats why I looked into doing it on the db server with SQL.
Reply With Quote
  #6 (permalink)  
Old 07-24-02, 17:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
the performance was bad in ASP?

then you must have been doing something wrong, like calling the database in a loop

call the database like this:
Code:
SELECT bookedTime 
  FROM tblBookedTimes 
INNER JOIN tblBookings 
    ON tblBookedTimes.fk_bookingID
     = tblBookings.pk_bookingID
 WHERE tblBookings.fk_carID=" & iCarID & " 
ORDER BY bookedTime
notice that you will get back all the bookedTime values for the car, and they will be in bookedTime sequence

now "cross-tab" the bookedTime values using ASP logic, laying them out into an array with zeroes in the "empty" spots...

there's no way that's going to have bad performance

laying out the results into an array should be easy, because from your original question it looks like all your datetime values were previously entered with times on the half hour (which makes sense for a booking table)

so just retrieve the data in one query (you may want to add a WHERE condition for the right date, and maybe get more info on which car, etc.), and ask an ASP programmer for help with the array

i guess i should mention that i don't do ASP

rudy
http://rudy.ca/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On