访问Access Rundate附近的最新数据

Access the most recent data near rundate from access

本文关键字:最新 数据 Access Rundate 访问      更新时间:2023-10-16

我正在通过SQL查询从Access DB检索记录。Origina查询检索最新日期数据。但是,如果我想运行该工具,例如3/3/2012,它仍将获取最新数据。但是我需要的数据要么等于2012年3月3日或接近3/3/2012但不超过日期的日期。例如,如果2012年3月3日不可用,并且在DB中可用3/2/2012,则应选择该日期。修改后的查询如下所示。它给出了保留的单词拼写错误或puctiuation的错误。在查询中,Trundate是我程序的输入。我的查询现在是:

cstring sel ="选择i.productType,i.spread,i.dateupep i.dateuppeed in mortgageratespreads i,(选择productType,max(dateupped)作为dateupdated1"; sel =" where dateupdated< =";
sel = trundate.format(" {ts'%y-%m-%d'}");

crecordset集(& pdatabase);

    try
    {
        double  val;
        CDBVariant var;
        if (set.Open(CRecordset::forwardOnly, sel/*, CRecordset::readOnly*/)) 
        {
            m_Log->Log("recordset is open");
            while (!set.IsEOF())

我的sel是:

sel "SELECT I.ProductType, I.Spd, I.DateUpdated FROM MRSpds I,(select ProductType, MAX(DateUpdated) AS DateUpdated1where DateUpdated <={ts '2012-02-08'  } FROM MRSpds GROUP BY ProductType) T WHERE I.ProductType = T.ProductType AND I.DateUpdated =T.DateUpdated1"

谢谢

            {               

我认为MS Access喜欢日期周围的#符号。dateUpdated&lt; =#3-3-2012#在sel =" where ..."中,您需要一个空间,例如sel =" where ..."另外,SQL语句中的日期字符串看起来像dateupdated&lt; =#3/3/2012#

另外,您的嵌套选择语句似乎具有从Where子句之后的子句。我认为应该像

(从MRSPDS中选择ProductType,Max(dateUpdepted)为dateUpded1,其中dateupdupded&lt; =##2012-02-08#by ProductType)t