Access与Sql中的不少语法及函数是不一样的,因此要分别对待,本次经验主要比较获取日期中的年份和月份,简单来说
sql用:DATEPART(yyyy,pDate)
Access用:Format(pDate,'YYYY')
如下2条查询语句,演示提取完整日期中的年份和月份(vb.net中)
Access数据库:
querystring = "select pName,pNum,pDate,pType,pNote,pTime,pUser,ID from INFO where Format(pDate,'YYYY')='" & tYear & "' and Format(pDate,'MM')='" & tMonth & "' and pName='" & selectProN & "' order by pDate desc"
sql数据库:
querystring = "select pName,pNum,pDate,pType,pNote,pTime,pUser,ID from INFO where DATEPART(yyyy,pDate)='" & tYear & "' and DATEPART(mm,pDate)='" & tMonth & "' and pName='" & selectProN & "' and pType='出货' order by pDate desc"