Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 查找日期板之间的记录(范围)_Sql_Date - Fatal编程技术网

Sql 查找日期板之间的记录(范围)

Sql 查找日期板之间的记录(范围),sql,date,Sql,Date,我创建了一个表格,在表格中输入了酒店的价格,以及这些价格有效的日期。如果我在特定酒店的价格中选择了特定日期,我希望在另一种形式中显示的是属于任何日期板下的特定日期,因为每个日期板都有不同的酒店价格 我试过这个 select * from test_hotelrates where Datefrom >= convert(date, '2013-10-01', 103) and Dateto <= convert(date, '2013-10-31', 103) and Season

我创建了一个表格,在表格中输入了酒店的价格,以及这些价格有效的日期。如果我在特定酒店的价格中选择了特定日期,我希望在另一种形式中显示的是属于任何日期板下的特定日期,因为每个日期板都有不同的酒店价格

我试过这个

select * from test_hotelrates where Datefrom >= convert(date, '2013-10-01', 103) 
and Dateto <= convert(date, '2013-10-31', 103) and Season = 'Season'
select*from test_hotelrates其中Datefrom>=convert(日期,'2013-10-01',103)

和Dateto它不起作用,因为您使用两个不同的日期进行比较。在本例中,您需要10月份所有天数的费率。我猜有人想在酒店住一个月。但我想你应该在这段时间内每天检查一下,看看当前的汇率。因为在这段时间里,利率可能会发生变化

您的查询将只返回2013年1月10日至2013年1月31日期间的费率

我认为您需要进行不同的查询或多次运行此查询

select * from test_hotelrates where Datefrom <= convert(date, '2013-10-01', 103) 
and Dateto >= convert(date, '2013-10-01', 103) and Season = 'Season'

select * from test_hotelrates where Datefrom <= convert(date, '2013-10-02', 103) 
and Dateto >= convert(date, '2013-10-02', 103) and Season = 'Season'

select * from test_hotelrates where Datefrom <= convert(date, '2013-10-03', 103) 
and Dateto >= convert(date, '2013-10-03', 103) and Season = 'Season'
test_hotelrates中选择*,其中Datefrom=convert(日期,'2013-10-01',103)和seasure='seasure'
从test_hotelrates中选择*,其中Datefrom=convert(日期,'2013-10-02',103)和Season='Season'
从test_hotelrates中选择*,其中Datefrom=convert(日期,'2013-10-03',103),Season='Season'

等等。

更改您的查询,如下所示:

select * from test_hotelrates where convert(varchar(10),Datefrom,103) >= convert(varchar(10), '2013-10-01', 103) 
and convert(varchar(10),Dateto,103) <= convert(varchar(10), '2013-10-31', 103) and Season = 'Season'
select*from test_hotelrates,其中convert(varchar(10),Datefrom,103)>=convert(varchar(10),'2013-10-01',103)
和转换(varchar(10),Dateto,103)