日期:2014-05-18 浏览次数:20483 次
create table OilPrice(startYear int,startMonth int,startDay int,endYear int,endMonth int,endDay int,oilprice float) insert into OilPrice values(2012,1,1,2012,2,1,1) insert into OilPrice values(2012,2,1,2012,3,1,2) insert into OilPrice values(2012,3,1,2012,4,1,3) insert into OilPrice values(2012,4,1,2012,5,1,4) insert into OilPrice values(2012,5,1,2012,6,1,5) insert into OilPrice values(2012,6,1,2012,7,1,6) go select * from oilprice /* startYear startMonth startDay endYear endMonth endDay oilprice ----------- ----------- ----------- ----------- ----------- ----------- ----------------------------------------------------- 2012 1 1 2012 2 1 1.0 2012 2 1 2012 3 1 2.0 2012 3 1 2012 4 1 3.0 2012 4 1 2012 5 1 4.0 2012 5 1 2012 6 1 5.0 2012 6 1 2012 7 1 6.0 (所影响的行数为 6 行) */ select * from OilPrice where cast('2012-03-22' as datetime) between cast(cast(startYear as varchar) + '-' + cast(startMonth as varchar) + '-' + cast(startDay as varchar) as datetime) and cast(cast(endYear as varchar) + '-' + cast(endMonth as varchar) + '-' + cast(endDay as varchar) as datetime) /* startYear startMonth startDay endYear endMonth endDay oilprice ----------- ----------- ----------- ----------- ----------- ----------- ----------------------------------------------------- 2012 3 1 2012 4 1 3.0 (所影响的行数为 1 行) */ drop table oilprice
------解决方案--------------------