sql access how to return between dates

前端 未结 4 2046
迷失自我
迷失自我 2020-12-11 18:29

How do I specify a date range in MS Access? Is the below query correct? Do I have to put \"2/1/2010\" in quotes? Or do I have to do something like date(2/

4条回答
  •  醉梦人生
    2020-12-11 19:14

    The dates to use in select (in Microsoft) are defined as: "#"+month+"/"+day+"/" +year+"#"

    the field day is a number 01,02---,31
    the field month is a number 01,02 ...12
    the field year is 2014, 2015 ...etc

    you can build the SQL field dinamically

    es. in vbscript

    dt1="#"&month(date1)&"/"&day(Date1)&"/"&year(Date1)&"#"
    dt2="#"&month(date2)&"/"&day(Date2)&"/"&year(Date2)&"#"
    

    and then you can use the select in a field SQL

    where the table Orders has a field named OrderDate es.

    SQL="select * from Orders where OrderDate Between " & dt1 & " and " dt2
    

    now you can access the Database

提交回复
热议问题