时间范围查询语句怎么写?

来源:百度知道 编辑:UC知道 时间:2024/05/28 19:00:58
我表里两个字段是"年","月".
我的查询条件是:StartYear,StartMonth,EndYear,EndMonth

查询语句应该怎么写呢,我被搅糊涂了....我用DELPHI写的.
ACCESS数据库

什么数据库?
MSSQL是
取month 是SELECT MONTH(GETDATE())
取year 是SELECT YEAR(GETDATE())
select * from 表
where StartYear > YEAR(GETDATE())
and EndYear < YEAR(GETDATE())
and StartMonth > MONTH(GETDATE())
and EndYear< MONTH(GETDATE())

oracle是相同道理

oracle是
select to_char(sysdate,'mm') from dual;
select to_char(sysdate,'yyyy') from dual;

select *
from table
where 年>StartYear and 年<EndYear
and 月>StartMonth and 月<EndMonth
其实逻辑上是不变的,只是被拆成两个字段了.如果必要的话把>换成>=

MS_SQL可这样有
select * from table where convert(varchar(6),时间,112) between '200901' and '300012'

where startyear||startmonth>to_char('200903','yyyymmdd')

select *
from table where startyear||startmonth>to_char('200903','yyyymmdd')