• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 705
  • Last Modified:

SQL, Delphi

Hi,

I'm changing my databases from *.dbf to sql
and i use ado components.

I used before FINDNEAREST, and now with  that doesn't work.

So i put code like this
TAble.Locate('FIELD',(s),[loCaseInsensitive,loPartialKey]).

And that work fine if field is align left, but some of my fields are align right, and then i have to
write exact word to find something.


I hope i was understandable

Thank you for your great solutions.
0
hrvica5
Asked:
hrvica5
  • 2
  • 2
2 Solutions
 
developmentguruPresidentCommented:
I would query the fields in a manner that makes your locate work.  As an example... if you have RightAlignedField as a field with right alignment you could do a query like this...

Select
  A,
  B,
  C,
  RightAlignField,
  LTrim(RightAlignField) NormalizedRAF
from
  MyTable


This would return an extra field that you could do your locate on, without worrying about the left padding.  I assume your SQL database will handle LTrim, if not then you will need to look up the trim function in your database.
0
 
Sinisa VukCommented:

Hi!

My first choice to do that is set OnFilter Event fot table, set Filtered property to True. Use
global variable for custom filtering.

OnFilter Event should look like this:

procedure Tform1.Table1FilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
  Accept:=Pos(sFilterStr,DataSet.FieldByName('Field').AsString)>0;
end;

Open in new window


Set property Table1.Filtered to False and then to True to refilter after change (using Edit1.OnChange event maybe)

Sinisa V.
0
 
developmentguruPresidentCommented:
If you would prefer to take the OnFilter approach you could also trim the field and use your normal logic.
0
 
Ephraim WangoyaCommented:

You could just do the search directly from your database

wher field like format('%s%s%s', [QuotedStr('%' + S + '%')]

or just trim the string

Table.Locate('FIELD', Trim(s), [loCaseInsensitive, loPartialKey]).
0
 
Ephraim WangoyaCommented:
oops, that was supposed to be
You could just do the search directly from your database

wher field like format('%s', [QuotedStr('%' + S + '%')]

or just trim the string

Table.Locate('FIELD', Trim(s), [loCaseInsensitive, loPartialKey])

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now