Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
SELECT *
FROM Room
LEFT JOIN booking ON (Room.RoomId = booking.RoomId)
WHERE booking.Roomid is null
  AND GETDATE() BETWEEN bookin.checkindate '" + TxtCheckIn.Text + "'
                AND booking.checkoutdate  '" + TxtCheckOut.Text + "'" + "
ORDER BY Room.RoomType

/*I want to check in the booking table if the date matches the checkin and checkout dates selected by users. If it doesn't match, the query should show all rooms in the room table (even if it is in the booking table), provided that they have different dates.*/
Posted
Comments
OPees 25-Jul-13 7:19am    
What is datatype of bookin.checkindate and booking.checkoutdate in table?
if its not datetime use convert method like convert(datatime,bookin.checkindate,103)
then compare

// Here 103 datetime format like 25/07/2013

Select CONVERT(varchar(100), GETDATE(), 120): 2006-05-16 10:57:49


check in the booking table if the date matches the checkin and checkout dates selected by users.


first:


SQL
SELECT *
FROM Room
LEFT JOIN booking ON (Room.RoomId = booking.RoomId)
WHERE booking.Roomid is null
  AND  CONVERT(varchar(100), GETDATE(), 120) BETWEEN bookin.checkindate '" + TxtCheckIn.Text + "'
                AND booking.checkoutdate  '" + TxtCheckOut.Text + "'" + "
ORDER BY Room.RoomType



second:

If it doesn't match, the query should show all rooms in the room table (even if it is in the booking table), provided that they have different dates.

select * from Room where ......
 
Share this answer
 
v2
I have tried it but i am having error

Incorrect syntax near '07/25/2013'.

SQL
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '07/25/2013'.



above is the error i get, thank, how do i resolve
thanks for your time, i really do appreciate
 
Share this answer
 

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