SQL, Delphi

Posted on 2011-10-03
Last Modified: 2013-11-23

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

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.
Question by:hrvica5
    LVL 21

    Accepted Solution

    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...

      LTrim(RightAlignField) NormalizedRAF

    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.
    LVL 25

    Assisted Solution

    by:Sinisa Vuk


    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);

    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.
    LVL 21

    Expert Comment

    If you would prefer to take the OnFilter approach you could also trim the field and use your normal logic.
    LVL 32

    Expert Comment


    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]).
    LVL 32

    Expert Comment

    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


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
    In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now