Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks

What is wrong with the following?

my $select_1="lan1"; my $select_2="lan2"; my $all_select = $dbh->selectall_arrayref("SELECT ID,lan1,lan2,lan3,la +n FROM table WHERE LOWER($select_1) LIKE '%$Word%' OR LOWER($select_ +1) LIKE '%$Word'");

what I want is to finde entries which contain $Word in column lan1 OR in column lan2. It now finds only $Word in column lang1.

Replies are listed 'Best First'.
Re: SQLite select or
by erix (Prior) on Nov 18, 2013 at 17:50 UTC
     OR LOWER($select_1) LIKE '%$Word'"

    Looks like you have forgotten the final % at the end of the second LIKE expression.

    It should be

     OR LOWER($select_1) LIKE '%$Word%'"

      thank you...this was the problem. Shame on me! 2 Hours try to understand what was wrong.

        Q:   Why do programmers have flat heads?
        A:   (whack!) “D‘oh!!!”

        This sort of thing happens to everyone.   More frequently than we usually care to admit.

Re: SQLite select or
by Corion (Patriarch) on Nov 18, 2013 at 15:52 UTC

    To help us help you better, please tell us the following information:

    What does your resulting SQL string look like?

    Does the resulting SQL string work when you paste it into the command line client?

Re: SQLite select or
by toolic (Bishop) on Nov 18, 2013 at 15:52 UTC
    Maybe because you never use $select_2 ?
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: SQLite select or
by NetWallah (Canon) on Nov 18, 2013 at 16:36 UTC
    You need to escape the percent signs, which are intended for SQL, such that they are not intrapolated by perl.

                 When in doubt, mumble; when in trouble, delegate; when in charge, ponder. -- James H. Boren