时间日期无效 ( 积分: 100 )

  • 主题发起人 主题发起人 tzmanlei
  • 开始时间 开始时间
T

tzmanlei

Unregistered / Unconfirmed
GUEST, unregistred user!
数据库类型 access
用dbf 数据库运行正常,但改为access数据库数类,则显示日期无效
datebegin1:=datetostr(datetimepicker1.Date);
dateend1:=datetostr(datetimepicker2.Date );
syear:=copy(datebegin1,1,4);
sqlstring:='select count(支付单位) as zc,sum(住院天数)as Zt,sum(治疗总费用) as ZF,sum(保内金额) as ZBf,sum(自费金额) as ZZ,sum(实际补偿金) as Zbc'
+' from 住院补偿'+syear+' where (就诊医院=:zfdw and 补偿日期>=:datebegin and 补偿日期<=:dateend and 状态=:zangtai)';

// sqlstring:='select count(支付单位) as zc,sum(住院天数)as Zt,sum(治疗总费用) as ZF,sum(保内金额) as ZBf,sum(自费金额) as ZZ,sum(实际补偿金) as Zbc'
// +' from 住院补偿'+syear+' where (就诊医院=:zfdw and 补偿日期>=:datebegin and 补偿日期<=:dateend and 状态="正常")';
// sqlstring:='select count(支付单位) as zc,sum(住院天数)as Zt,sum(治疗总费用) as ZF,sum(保内金额) as ZBf,sum(自费金额) as ZZ,sum(实际补偿金) as Zbc'
// +' from 住院数据.dbf where 就诊医院=:zfdw and 补偿日期>=:datebegin and 补偿日期<=:dateend and 状态="正常"';
query1.SQL.Clear ;
query1.SQL.Add(sqlstring);
query1.ParamByName('zfdw').AsString :=datamodule1.yljgTable.Fields[2].AsString ;
query1.ParamByName('datebegin').asdate :=strtodate(datebegin1) ;
query1.ParamByName('dateend').Asdate :=strtodate(dateend1) ;
query1.ParamByName('zangtai').AsString :='正常';
query1.Open;
请哪位老兄指教
 
syear:=copy(datebegin1,1,4);
' from 住院补偿'+syear+' where
是不是这有问题
 
在SQL.clear和SQL.add;前要有SQL.close;
 
syear:=copy(datebegin1,1,4);
' from 住院补偿'+syear+' where
这个是正确的,我在sql explorer中写的查询语名
select count(支付单位) as zc,sum(住院天数)as Zt,sum(治疗总费用) as ZF,sum(保内金额) as ZBf,sum(自费金额) as ZZ,sum(实际补偿金) as Zbc
from 住院补偿2007 where (就诊医院='湘潭县中医院' and 补偿日期>=2007-1-1 and 补偿日期<=2007-5-5 and 状态='正常');
不能运行,
但放在access 查询中却能正确运行
 
不知道这个#2007-1-1#到底是什么意思
 
我没有遇到这种问题了,你看哈数据库中的日期/时间类型和2007-01-01一至不??
要不这样:

query1.ParamByName('datebegin').asdate :=strtodate(datebegin1) ;
query1.ParamByName('dateend').Asdate :=strtodate(dateend1) ;
改为:
query1.ParamByName('datebegin').asdate :=DateTimePicker1.Date ;
query1.ParamByName('dateend').Asdate :=DateTimePicker2.Date ;
 
你怎么连接数据库的?BDE?ADO?还是ODBC?
ODBC连接数据库和BDE连接时候写的SQL语句格式是不一样的。
#2007-1-1#
是Access的日期时间表示方法。
比如like语句在ADO连的时候这么写:like '%dd%'
ODBC里面是这么写: like '*dd*'

在改别人程序吧?用ODBC连看看也就没问题了。
 
我是用odbc
这是我自已开发的一个合作医疗程序,
datebegin1:=datetostr(datetimepicker1.Date);
dateend1:=datetostr(datetimepicker2.Date );
syear:=copy(datebegin1,1,4);
sqlstring:='select count(支付单位) as zc,sum(住院天数)as Zt,sum(治疗总费用) as ZF,sum(保内金额) as ZBf,sum(自费金额) as ZZ,sum(实际补偿金) as Zbc'
+' from 住院补偿'+syear+' where (就诊医院=:zfdw and 补偿日期>=:datebegin and 补偿日期<=:dateend and 状态=:zangtai)';

query1.SQL.Clear ;
query1.SQL.Add(sqlstring);
query1.ParamByName('zfdw').AsString :=datamodule1.yljgTable.Fields[2].AsString ;
query1.ParamByName('datebegin').AsDate:=datetimepicker1.Date ;
query1.ParamByName('dateend').AsDate:=datetimepicker2.Date ;
query1.ParamByName('zangtai').AsString :='正常';
query1.Open;
我试了很多种办法都不行,就是access的日期格试#2007-1-1#不能用参数传递过去
 
'...补偿日期 BETWEEN #:DateBegin# AND #:DateEnd# .....'
Query1.ParamByName('DateBegin').AsString := FormatDateTime('yyyy-mm-dd', DateTimePicker1.Date);
Query1.ParamByName('DateEnd').AsString := FormatDateTime('yyyy-mm-dd', DateTimePicker2.Date);
 
路过,试下面方法吧

query1.ParamByName('zfdw').AsString :=QuotedStr(datamodule1.yljgTable.Fields[2].AsString);
query1.ParamByName('datebegin').AsString:=QuotedStr(FormatDateTime('yyyy-mm-dd', DateTimePicker1.Date));
query1.ParamByName('dateend').AsString:=QuotedStr(FormatDateTime('yyyy-mm-dd', DateTimePicker2.Date));
query1.ParamByName('zangtai').AsString :=QuotedStr('正常');
 
不要用query1.ParamByName方法


sqlstring:='select count(支付单位) as zc,sum(住院天数)as Zt,sum(治疗总费用) as ZF,sum(保内金额) as ZBf,sum(自费金额) as ZZ,sum(实际补偿金) as Zbc'
+' from 住院补偿'+syear+' where (就诊医院='''+datamodule1.yljgTable.Fields[2].AsString+'''and 补偿日期>=#'+'2007-1-1+ '# and .....

其中2007-1-1自己用datebegin1换入
 
多人接受答案了。
 
41426277 你的方法,程序虽然能运行了,但是,统计不出数据
 
后退
顶部