本文介绍了如何通过DATE值常量过滤FireDAC数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

procedure TForm2.Button1Click(Sender: TObject);
begin
  with qryWithFilter do
  begin
    Filtered := False;
    OnFilterRecord := nil;
    // date separator may be used any from [' ', '-', '\', '.', '/']
    // Filter := 'DATA_NAS < (''DatetoStr(date3)'')';
    // Filter := 'DATA_NAS < ''28/06/1939''';
    // Filter := 'DATA_NAS < (FormatDateTime(''dd/mm/yyyy'', ''28/06/1968''))';
    // Filter := 'DATA_NAS < TO_DATE(''1996-07-29'',''yyyy-mm-dd'')';
    Filter := 'DATA_NAS < (TO_DATE(''1996-07-29'',''yyyy-mm-dd''))';
    Filtered := True;
  end;
end;

仅与 ’28 / 06/1968一起使用。我得到的错误是:

Only work with ''28/06/1968''. The error I'm getting is:

如何通过DATE值常量过滤FireDAC查询?

How can I filter my FireDAC query by a DATE value constant?

推荐答案

FireDAC的属性实现不支持DBMS功能,但为您提供了自己的表达式引擎。

The FireDAC's Filter property implementation doesn't support DBMS functions, but offers you their own expression engine.

使用FireDAC将字符串常量转换为在属性表达式可以像使用宏功能或转义序列。然后,表达式引擎为您选择特定于DBMS的转换函数。

With FireDAC converting a string constant into a DATE type value in the Filter property expression can be as simple as using the CONVERT macro function or {d} escape sequence. The expression engine then picks a DBMS specific conversion function for you.

尝试以下过滤器之一(所有变体的日期字符串格式为 yyyy-mm-dd ):

Try one of these filters (date string format for all variants is yyyy-mm-dd):

uses
  FireDAC.Stan.ExprFuncs;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with FDQuery do
  begin
    { disable filter }
    Filtered := False;
    { filter with date escape sequence (is nicely readable) }
    Filter := 'DATA_NAS < {d 1996-07-29}';
    { filter with CONVERT macro function without function escape sequence }
    Filter := 'DATA_NAS < {CONVERT(''1996-07-29'', DATE)}';
    { filter with CONVERT macro function with function escape sequence }
    Filter := 'DATA_NAS < {fn CONVERT(''1996-07-29'', DATE)}';
    { enable filter }
    Filtered := True;
  end;
end;

这篇关于如何通过DATE值常量过滤FireDAC数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 11:07