有一个表COST里面有个DATE字段TYPE是DATE型。数据格式是2007-02-15
我现在想在DELPHI实现按照月份提取数据,比如在COMBOBOX的下拉列表中选择2就能查询出所有2月份的的数据。
我原来写的代码是
query1.DatabaseName :='d:\';
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select * from cost where month(date)='+''''+combobox2.text+'''');
query1.Open;
运行的时候报错 invalid use of keyword token:month(date)='2'//因为我选择的是2月份。
但是在SQL中运行SELECT * from cost where month(date)='2'能执行,也能查处数据。请大家帮帮忙吧,急
数据是写在VF表中,是DATE型
我现在想在DELPHI实现按照月份提取数据,比如在COMBOBOX的下拉列表中选择2就能查询出所有2月份的的数据。
我原来写的代码是
query1.DatabaseName :='d:\';
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select * from cost where month(date)='+''''+combobox2.text+'''');
query1.Open;
运行的时候报错 invalid use of keyword token:month(date)='2'//因为我选择的是2月份。
但是在SQL中运行SELECT * from cost where month(date)='2'能执行,也能查处数据。请大家帮帮忙吧,急
数据是写在VF表中,是DATE型
query1.SQL.Add('select * from cost where month(date)='+QuotedStr(comboBox2.text));
一样的是invalid use of keyword token:month(date)='2
query1.SQL.Clear;
query1.SQL.Add('select * from cost where TYPE between '+quotedStr('2007-'+combobox2.text+'1')+' and '+QuotedStr('2007-'+IntToStr(StrtoInt(combobox2.text)+1)+'-1');
query1.Open;
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select * from cost where TYPE between '+quotedStr('2007-'+combobox2.text+'-1')+' and '+QuotedStr('2007-'+IntToStr(StrtoInt(combobox2.text)+1)+'-1');
query1.Open;
还有你这样的查询有什么意思呀.呵呵,月份等于2月,年份居然不考虑 .呵呵
where date >= 该月的第一天 and date < 下月的第一天