in reply to Re^3: wild cards in Vertica
in thread wild cards in Vertica

Yes..the prefix is always like A or B or M etc. I tried this way
if ($clnm ne ""){ $cnt = @parts = split(/\,/, $clnm ); # $clnm = "'"; $WHERE = $WHERE ." AND ("; for ($i = 0; $i < $cnt; $i++) { $WHERE = $WHERE . "m.CLNAME LIKE '$parts[$i]%' "; ($WHERE = $WHERE . " OR ") if ($i < $cnt - 1); } $WHERE = $WHERE . ")"; }
but still did not work. getting output as: AND m.CLNAME IN (A,BDO-CL1) Should I modify here too?
if ($clnm ne "") { $Where = $Where . "AND m.CLNAME IN ($clnm) "; }
Thanks,

Replies are listed 'Best First'.
Re^5: wild cards in Vertica
by GotToBTru (Prior) on Jun 30, 2015 at 19:25 UTC

    Saying it doesn't work doesn't help. For the THIRD time, please answer my very simple question .. what value do you want to see in $Where?

    Dum Spiro Spero
      I need to see WHERE m.processed_time BETWEEN to_timestamp('20150630003500','YYYYMMDDHH24MISS') AND to_timestamp('20150630020559', 'YYYYMMDDHH24MISS')AND CLName LIKE('A%','MET-CL1',BDO-CL1')

        If you typed that in, would your database accept it? That doesn't look valid to me. I would expect something more like:

        WHERE ... AND ((CLName LIKE 'A%') OR (CLName in ('MET-CL1','BDO-CL1'))

        The following will divide the provided values into two arrays, @pre to hold prefixes, @words to hold complete values. It assumes one letter by itself is a prefix. Anything else is a complete value.

        if ($clnm) { @parts = split /,/,$clnm; map { m/\'\w\'/ ? push @pre, $_ : push @words, $_ } @parts;

        Functions like join can be used to format the LIKE clause and the IN clause. Here's one way to construct the IN clause:

        $in_clause = sprintf "( CLName IN (%s) )", join ',',@words;

        Then you will need some logic to figure out what connecting terms (AND, OR) you will need.

        Dum Spiro Spero

        If I'm reading you correctly:

        AND CLName LIKE('A%','MET-CL1',BDO-CL1')

        Should become:

        AND ( CLName LIKE 'A%' OR CLName LIKE '%MET-CL1%' OR CLName LIKE '%BDO-CL1%' )