搜索数据库以获取使用mssql之间的日期 [英] search the database to get date between using mssql

查看:76
本文介绍了搜索数据库以获取使用mssql之间的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.*/

推荐答案

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





如果日期与用户选择的登记和结账日期相符,请在预订表中查询。





优先:





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:


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 ......


我试过但我有错误



附近的语法不正确07/25/2013'。



I have tried it but i am having error

Incorrect syntax near '07/25/2013'.

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


这篇关于搜索数据库以获取使用mssql之间的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆