VB中有cmbYear1,cmbYear2,cmbMonth1,cmbMonth2四个下拉列表框.选择年和月,查询出相关的数据
表里面有年,月,日三个字段.
2006 1 至 2006 12 
2006 1 至 2007 12
2006 1 至 2008 12
有这三种情况.请问如何判断年月的SQL语句怎么写????

解决方案 »

  1.   

    其实你的年月日完全可以合成一个日期型字段的.select * from 表 where (年* 100+月) >= (Year1*100 + Month1)
    and (年* 100+月) <= (Year2*100 + Month3)
      

  2.   

    就直接把年月日三字段拼起来就行了
    如:sql ="select * from table where 年+月 between " cmbYear1 & cmbMonth1 " and " cmbYear2 & cmbMonth2
      

  3.   

    楼上的写法有问题。
    数据库中是整型,那么 cmbYear1 & cmbMonth1  也应该用数字相加。否则会出问题.
      

  4.   

    ……
    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
    ……
    应该可以的
      

  5.   

    是整型的吗?
    那就这样
    sql ="select * from table where cast(年 as varchar(2))+cast(月 as varchar(2)) between " cmbYear1 & cmbMonth1 " and " cmbYear2 & cmbMonth2