DataM中的表Employee,
想对其的dept(部门)进行过滤
但下列的代码却出错,
怎么改?procedure TDataM.EmployeeBeforeOpen(DataSet: TDataSet);
begin
if pub.LoginDcode<>'' then
begin
Employee.Filtered := false;
Employee.Filter := 'left(dept,'+IntToStr(length(LoginDcode))+')='''+pub.LoginDcode+'';
Employee.Filtered := true;
end
end;
Operator Meaning
< Less than
> Greater than
>= Greater than or equal to
<= Less than or equal to
= Equal to
<> Not equal to
AND Tests two statements are both True
NOT Tests that the following statement is not True
OR Tests that at least one of two statements is True
+ Adds numbers, concatenates strings, adds numbers to date/time values (only available for some drivers)
- Subtracts numbers, subtracts dates, or subtracts a number from a date (only available for some drivers)
* Multiplies two numbers (only available for some drivers)
/ Divides two numbers (only available for some drivers)
* wildcard for partial comparisons (FilterOptions must include foPartialCompare)
By using combinations of these operators, you can create fairly sophisticated filters. For example, the following statement checks to make sure that two test conditions are met before accepting a record for display:(Custno > 1400) AND (Custno < 1500);NoteWhen filtering is on, user edits to a record may mean that the record no longer meets a filter's test conditions. The next time the record is retrieved from the dataset, it may therefore "disappear." If that happens, the next record that passes the filter condition becomes the current record.
其实就是:left(dept,2)=01我试了不用left可以还有别的办法吗?
function LeftStr(const AText: string; const ACount: Integer): string;
unit StrUtils.pas
功能 返回字符串AText左边的ACount个字符
说明 LeftStr('123456', 3) = '123'
参考 function System.Copy
例子 Edit3.Text := LeftStr(Edit1.Text, SpinEdit1.Value);Employee.Filter := 'left(dept,'+IntToStr(length(LoginDcode))+')='''+pub.LoginDcode+'';
改为
Employee.Filter := format('%s=%s', [LeftStr(dept,length(LoginDcode),QuotedStr(pub.LoginDcode)]);
这种 语句不能用Filter ,你还是用sql语句吧