VB.NET中的预约查询

时间:2015-11-19 14:18:29

标签: sql-server vb.net

我正在预订系统,我希望在进行新预订时获取DataGridView的房间详细信息。房间详细信息位于一个名为service的表中,预订详细信息位于items_reserved表中。在每次预订时,我都需要检查日期和时间。

如果我只考虑日期,以下查询效果很好:

"SELECT * FROM Service " &
"WHERE Service_Type_ID= '" & txtBoxSerType.Text & "'" &
"  AND Service_ID NOT IN (" &
"          SELECT Service_ID FROM Items_Reserved" &
"          WHERE Date_In <= '" & DateTimePickerDateOut.Text & "'" &
"            AND Date_Out >= '" & DatePickerDateIn.Text & "'" &
"            AND Status Is Null" &
"      )"

但我还需要检查时间限制。以下查询是我尝试过的,但遗憾的是它无效:

"SELECT * FROM Service " &
"WHERE Service_Type_ID= '" & txtBoxSerType.Text & "'" &
"  AND Service_ID NOT IN (" &
"          SELECT Service_ID FROM Items_Reserved" &
"          WHERE Date_In <= '" & DateTimePickerDateOut.Text & "'" &
"            AND Date_Out >= '" & DatePickerDateIn.Text & "'" &
"            AND Status Is Null" &
"            AND Service_ID Not In (" &
"                    SELECT Service_ID FROM Items_Reserved" &
"                    WHERE Date_In = '" & DateTimePickerDateOut.Text & "'" &
"                      AND Time_In <= '" & DateTimePickerTimeOut.Text & "'" &
"                      AND Status Is Null" &
"                      AND Service_ID Not In (" &
"                              SELECT Service_ID FROM Items_Reserved" &
"                              WHERE Date_Out = '" & DatePickerDateIn.Text & "'" &
"                                AND Time_Out >='" & DateTimePickerTimeIn.Text & "'" &
"                                AND Status Is Null" &
"                          )" &
"                )" &
"      )"

例如,假设Room1有一个预留位置:

  • DateIn = 11/15/2015
  • DateOut = 11/17/2015
  • TimeIn = 12:00
  • TimeOut = 14:00

当我使用给出的第二个查询时,输入新的预订详细信息以检查可用房间:

  • DateIn = 11/17/2015
  • DateOut = 11/20/2015
  • TimeIn = 18:00
  • TimeOut = 08:00

理想情况下,Room1应显示为可用。

0 个答案:

没有答案