求一句SQL的检索用WHERE语句

来源:百度知道 编辑:UC知道 时间:2024/06/18 15:19:06
目前,在程序中有2个变量
String dateFrom = "200207"; // 表示从2002年7月开始
String dateTo = "200508"; // 表示到2005年8月为止

且这俩个变量是随时都会改变的,单格式一直为"YYYYMM"
而数据库的表中有一日期型字段"TEST_DATE"
求一句最简单的SQL文的WHERE语句
把"TEST_DATE"是在dateFrom到dateTo之间(包括)的所有数据都取出来??

**请尽量只用WHERE语句来达到效果,不要在执行该SQL语句前对dateFrom和dateTo进行处理,直接在WHERE语句中使用。

备注一下,目前使用的数据库是ORECAL。

谢谢大家了!!!

select * from table where test_date between to_date(dateFrom,'yymm') and to_date(dateto,'yymm')

不知道这个是不是你想要的!

select * from table where to_char(test_date,'yyyymm') between to_date(dateFrom,'yyyymm') and to_date(dateto,'yyyymm')

where covert(char,(datepart(year,TEST_DATE)*10+datepart(month,TEST_DATE)))>=dateFrom
and covert(char,(datepart(year,TEST_DATE)*10+datepart(month,TEST_DATE)))<=dateTo