我想知道您是否可以看看我在Delphi上进行日期比较的代码。
DELPHI中的代码片段:-
// SQL QUERY to gather member information.
DMS.ADOQuery1.SQL.Clear;
DMS.ADOQuery1.SQL.Add('select HPFROMDT, HPthruDt, MEMBERKEY, MEMBHPKEY, OPFROMDT, OPTHRUDT, HPCODEKEY' +
' from MEMBHP' +
' where MEMBERKEY = ''' + MembKey + ''' and OPFROMDT <= ''' + date_request + ''' and OPTHRUDT > ''' + date_request +''' 'SQL中的脚本片段:-
SELECT [MEMBHPKEY]
,[MEMBERKEY]
,[CURRHIST]
,[HPFROMDT]
,[OPFROMDT]
,[OPTHRUDT]
,[HPCODEKEY]
,[HPOPTIONKEY]
FROM [main].[dbo].[*****]
where MEMBERKEY = '1234567' and OPFROMDT <= '2007-08-01' and OPTHRUDT > '2007-08-01'SQL脚本显然将常量日期值与提取的日期值进行比较。而且起作用了!
然而,Delphi代码不起作用。错误信息
将字符串转换为小日期类型时,转换失败。
我相信德尔福必须有某种转换技术,它应该允许我转换成正确的变量类型…。。有什么想法吗?
我从文本文件中提取date_request作为字符串变量.
for i := 11 to length(buffer) do
begin
DT_request := DT_request + buffer[i];
end;发布于 2012-10-29 16:14:55
使用参数..。
AdoQuery1.SQL.TExt:
Declare @Date smalldatetime
Select @Date=:Date
SELECT [MEMBHPKEY]
,[MEMBERKEY]
,[CURRHIST]
,[HPFROMDT]
,[OPFROMDT]
,[OPTHRUDT]
,[HPCODEKEY]
,[HPOPTIONKEY]
FROM [main].[dbo].[MEMBHP]
where MEMBERKEY =:memberkey and OPFROMDT <= @Date and OPTHRUDT > @Date
AdoQuery1.Parameters.ParseSQL(AdoQuery1.SQL.TExt,true);
AdoQuery1.Parameters.ParamByName('Date').DataType := ftDatetime;
AdoQuery1.Parameters.ParamByName('Date').Value := StrToDate('1.1.2012');
AdoQuery1.Parameters.ParamByName('memberkey').Value := 123;https://stackoverflow.com/questions/13125373
复制相似问题