VB中有cmbYear1,cmbYear2,cmbMonth1,cmbMonth2四个下拉列表框.选择年和月,查询出相关的数据
表里面有年,月,日三个字段.
2006 1 至 2006 12
2006 1 至 2007 12
2006 1 至 2008 12
有这三种情况.请问如何判断年月的SQL语句怎么写????
表里面有年,月,日三个字段.
2006 1 至 2006 12
2006 1 至 2007 12
2006 1 至 2008 12
有这三种情况.请问如何判断年月的SQL语句怎么写????
and (年* 100+月) <= (Year2*100 + Month3)
如:sql ="select * from table where 年+月 between " cmbYear1 & cmbMonth1 " and " cmbYear2 & cmbMonth2
数据库中是整型,那么 cmbYear1 & cmbMonth1 也应该用数字相加。否则会出问题.
dim date1 as date
dim date2 as date
date1=cmbYear1.caption &'"& 月 &"& cmbMonth1.caption &'"& 日 &"'
date2=cmbYear2.caption &'"& 月 &"& cmbMonth2.caption &'"& 日 &"'rs.open "select * from 表1 where 日期<= #" & date2 & "# and 日期>=#" & date1 & "#",cn,2,3
……
应该可以的
那就这样
sql ="select * from table where cast(年 as varchar(2))+cast(月 as varchar(2)) between " cmbYear1 & cmbMonth1 " and " cmbYear2 & cmbMonth2