如m_pRecordset.Open("select bno,sum(cash) as cash_sum from sale group by bno having sum(cash)>0 order by bno",.......)
现在如果sale表中有日期date_字段,我想取一个时间段,该如何做?
我用了m_pRecordset.PutFilter(_variant_t("date_>'20030101'"));
可程序报错无法执行,为何??

解决方案 »

  1.   

    m_pRecordset.Open("select bno,sum(cash) as cash_sum from sale where date_>'20030101' group by bno having sum(cash)>0 order by bno",.......)
      

  2.   

    我知道是这么写,可我需要在程序中通过变量来进行过滤记录。
    如我在程序界面上允许用户限定一个日期进行查询,然后我需要用PutFilter进行过滤。这该如何办呢??
      

  3.   

    主要可能是用了GROUP BY的缘故。
      

  4.   

    FILTER是对RecordSet的结果集进行过滤用的。你的m_pRecordset.Open打开的结果集总并没有
    date_这个字段,所以进行过滤的时候出错。可以考虑这么做
    将m_pRecordset.Open打开的SQL语句设置为变量。sqlstr = "select bno,sum(cash) as cash_sum from sale where date_>'''+m_date+''' group by bno having sum(cash)>0 order by bno";//m_date为界面上传进来的查询日期
      //通过这种方式构筑一个动态SQL语句就可以了。
    m_pRecordset.Open(sqlstr ,....);我对VC也不是很熟了,不过大概就是这样子的了。