我创建了一个库,里面有DATE 销售的日期
现在我想查询哪年哪月哪日的记录 应该怎么查呢?
例如我想要查询2003的记录怎么查呢?
又如要查询2003年5月分的记录应该怎么查呢?
"select * from sell year(date)='" & text1.text & "'"
这样不行啊

解决方案 »

  1.   

    "select * from sell where year(date)=#" & text1.text & "#"
      

  2.   

    哪年哪月那日,"select * from sell where year(date)=2003 and month(date)=5 and day(date)=1"
    哪年哪月"select * from sell where year(date)=2003 and month(date)=5"
      

  3.   

    select * from sell where year(date)='" & text1.text & "'"
      

  4.   

    不行啊,怎么我的查询结果是不对的呢?老说没有记录啊
    Dim mrc As ADODB.Recordset
        txtsql = "select * from sell where "
        If ComboYear.Text = "" Then
                smeg = "请选择年份!"
                MsgBox smeg, vbOKOnly + vbExclamation, "警告"
                Exit Sub
                ComboYear.SetFocus
        Else
                txtsql = txtsql & "year(销售时间) ='" & ComboYear.Text &"'"
        End If
      
        
        If ComboMonth.Text = ""  Then
        Else
            txtsql = txtsql & "and month(销售时间) ='" & ComboMonth.Text & "'"
        End If
        
        If ComboDay.Text = "" Then
        Else
            txtsql = txtsql & "and day(sell.销售时间)='" & ComboDay.Text & " '"
        End If    
        txtsql = txtsql & " order by 销售编号"
        Set mrc = ExecuteSQL(txtsql, msgtext)'这是我定义的数据连接函数 没有问题的
      

  5.   

    liangfang(良芳)说得对,在vb里面日期的查询需要加上##