Skip to content
Tako Lee edited this page Feb 17, 2014 · 9 revisions
  • Condition with logical structure

    Switch parentheses, which structure interlaced logical expressions into a new line. Turn this SQL

    SELECT f 
    FROM   t 
    WHERE 
      test1 IN ( 'Group1', 'Group2', 'Group3', 'Group4' ) 
      AND ( test2 IS NULL 
             OR test2 NOT IN ( 'Group3', 'Group5' ) 
             OR ( ( test2 IN ( 'Group3', 'Group4' ) 
                    AND test3 <> 10 ) 
                  AND NOT ( test2 IN ( 'Group6', 'Group7' ) 
                            AND test3 = 20 ) ) ) 
      AND test4 NOT IN ( 7654321, 1234567 ) 

into

SELECT f 
FROM   t 
WHERE 
  test1 IN ( 'Group1', 'Group2', 'Group3', 'Group4' ) 
  AND 
  ( 
    test2 IS NULL 
     OR test2 NOT IN ( 'Group3', 'Group5' ) 
     OR 
    ( 
      ( 
        test2 IN ( 'Group3', 'Group4' ) 
        AND test3 <> 10 
       ) 
      AND NOT 
          ( 
            test2 IN ( 'Group6', 'Group7' ) 
            AND test3 = 20 
           ) 
     ) 
   ) 
  AND test4 NOT IN ( 7654321, 1234567 ) 
  • String concate with max line width
Clone this wiki locally