我现在有个时间变量date1,,date2 想与表中Time字段中值做比较,选出大于或小于的记录 date1的形式为YYYY-mm-dd 而表中设置字段Time的类型为vachar(20),要怎么写语句,请大侠帮忙修改下列语句
with query1 do
begin
close;
SQL.Clear;
SQL.Add('select × from PlanInfo,ProInfo where PlanInfo.ID =ProInfo.ID ');
SQl.Add('and Time > date1 and TimePlanEnd < date2');
Open;
end;
with query1 do
begin
close;
SQL.Clear;
SQL.Add('select × from PlanInfo,ProInfo where PlanInfo.ID =ProInfo.ID ');
SQl.Add('and Time > date1 and TimePlanEnd < date2');
Open;
end;
解决方案 »
- delphi 发消息 C#接收消息 的问题
- treeview onchange事件里如何得到change前的节点信息
- 简单问题求解
- dll调用,程序退出时报错!
- Memo控件的OnMouseDown或OnMouseUp事件中的X,Y值为什么每次点击同一地方时都不同,怎样才能得到准确不变的X,Y值?
- WideCharToMultiByte的问题 ,高分相送。。在线等待。。。
- sql操作的问题
- 当用midas 用applyupdata提交的时候到底是...如果提交到一半的时候掉线了...
- Dispatch的汇编代码如何理解?
- 如何在运行表单时最小化,完成后复原.还有如何将光标定位maskedit
- delphi串口Spcomm
- --------- 转让 即时通讯源码------------
with query1 do
begin
close;
SQL.Clear;
SQL.Add('select × from PlanInfo,ProInfo where PlanInfo.ID =ProInfo.ID ');
SQl.Add('and Time > convert(varchar(20), date1, 120) and TimePlanEnd < convert(varchar(20), date2, 120)');
Open;
end;
with query1 do
begin
close;
SQL.Clear;
SQL.Text:='select * from PlanInfo,ProInfo where PlanInfo.ID =ProInfo.ID AND convert(varchar(10),Time,120) >'+QuotedStr(date1)+' AND convert(varchar(10),TimePlanEnd,120) <'+QuotedStr(date2);
Open;
end;
CAST 和 CONVERT
将某种数据类型的表达式显式转换为另一种数据类型。CAST 和 CONVERT 提供相似的功能。语法
使用 CAST:CAST ( expression AS data_type ) 使用 CONVERT:CONVERT (data_type[(length)], expression [, style])expression是任何有效的 Microsoft® SQL Server™ 表达式。有关更多信息,请参见表达式。 data_type目标系统所提供的数据类型,包括 bigint 和 sql_variant。不能使用用户定义的数据类型。有关可用的数据类型的更多信息,请参见数据类型。 lengthnchar、nvarchar、char、varchar、binary 或 varbinary 数据类型的可选参数。 style日期格式样式,借以将 datetime 或 smalldatetime 数据转换为字符数据(nchar、nvarchar、char、varchar、nchar 或 nvarchar 数据类型);或者字符串格式样式,借以将 float、real、money 或 smallmoney 数据转换为字符数据(nchar、nvarchar、char、varchar、nchar 或 nvarchar 数据类型)。SQL Server 支持使用科威特算法的阿拉伯样式中的数据格式。
date1和date2是Tdate 形式yyyy-mm-dd,数据库表中Time的类型为vachar(20),形式也为yyyy-mm-dd,大侠再帮帮忙
with query1 do
begin
close;
SQL.Clear;
SQL.Text:='select * from PlanInfo,ProInfo where PlanInfo.ID =ProInfo.ID AND '+
'convert(varchar(10),Time,120) >:date1 AND convert(varchar(10),TimePlanEnd,120) <:date2';
parameters.Parambyname('date1').value := date1;
parameters.Parambyname('date2').value := date2;
Open;
end;