Click here to Skip to main content
14,975,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on vehicle booking system. Now I have a particular vehicle booked for a period of time. let say 15-01-2013 to 31-01-2013. What i want that if another user try to book this vehicle and his date falls in between this range, then he must not be allowed to do so. 3 cases possible for this.
1. date period like 7-01-2013 to 20-01-2013. NOT ALLOWED due to end date within booking period.
2. date period like 20-01-2013 to 05-02-2013. NOT ALLOWED due to start date within booking period.
3. date period like 7-01-2013 to 05-01-2013. NOT ALLOWED due to full period within booking period.

How can i write query in MySQL for this??
Posted

1 solution

you will be having vehicle id know use that for example vehicle id is v1 and the booking date is between 15-01-2013 and 31-01-2013
then in procedure
SQL
 create procedure prcVehicle
 (
     vehicleId varchar(10),
     dtBookingDate date
 )
 begin
    declare cnt,x int;
    select count(*) from tablename where fieldname=vehicleId and fieldname for date >15-01-2013 and   fieldname for date <31-01-2013
 if cnt>0
    set x=0;
    select x;
 else
   your insert statement
   set x=1;
   select x;
 end if;
end


then in front end if $res['x']=0 then already booked else can book
   
Comments
Shakil Sama 25-Mar-13 8:36am
   
Thx. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900