Checking available room resevation between check-in and check-out date with SQL in ASP.net -


i use advice in how create select statement, work check-in , check-out dates. have 2 tables: rooms , booking. understand, this:

rooms table: room number (prim-key) type price  booking table: bookingid (prim-key) check-in date: check-out date: room-number (foreign key) room number in room table. 

i have check available room button run select statement in gridview. based on input user should find rooms not reserved already.

the datatype of check-in , check-out "date" dd/mm/yyy" lets if room 101 booked between 13-07-2015 , 15-07-2015. table looks this.

bookingid = long number  ,   check-in = 13-07-2015  ,   check-out = 15-07-2015  ,  roomnumber = 101. 

so , how make select statement if user writes in dates: 14-07-2015 16-07-2015? should not show room 101, because it's reserved.

hope can guide me in right direction. if need code or , please let me know!

update:

i'm still trying make work.. not sure causing issues got. right when run code tim , hogan (tried them both) retrieve room in hotel, , not sort specific rooms out reserved.

as see @ picture below, room 102 reserved

code of text boxes users write in dates:

 <div class="form-group">     <asp:label id="checkinlabel" runat="server" text="check-in date"></asp:label>     <asp:textbox id="datetimepicker1" clientidmode="static" runat="server" cssclass="form-control"></asp:textbox>  </div>  <div class="form-group">     <asp:label id="checkoutlabel" runat="server" text="check-out date"></asp:label>     <asp:textbox id="datetimepicker2" clientidmode="static" runat="server" cssclass="form-control"></asp:textbox>     </div> 

pictures of 2 tables, can see how like:

enter image description here

the checkin , checkout datatype is: nchar(10) , have tried "date" datatype given me following error "conversion failed when converting date and/or time character string."

enter image description here

the important thing here, if tries reserve room , check-in or check-out date date between 15-07-2015 - 20-07-2015 room 102 reserved , should not shown.

i think tim misses 1 case -- using between make logic clearer maybe?

edit: nevermind, tim's correct -- here way it.

the cases -- our checkin or checkout sometime between when room used or our checkin , checkout "surround" when room used.

select r.* room r not exists (     select 1 booking b     b.roomnumber = r.roomnumber      ,      (          @checkin between b.checkin , b.checkout or          @checkout between b.checkin , b.checkout or           (@checkin <= b.checkin , @checkout >= b.checkput     ) ) 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -