<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>SQLinForm Forum - Examples</title>
        <description>In this forum you will find a few examples how the different formatting options work. You are very welcome to comment and to add your own examples.</description>
        <link>http://www.sqlinform.com/forum4/list.php?4</link>
        <lastBuildDate>Wed, 19 Jun 2013 18:17:12 +0200</lastBuildDate>
        <generator>Phorum 5.2.10</generator>
        <item>
            <guid>http://www.sqlinform.com/forum4/read.php?4,22,22#msg-22</guid>
            <title>&quot;Show indentation Level&quot; (1 reply)</title>
            <link>http://www.sqlinform.com/forum4/read.php?4,22,22#msg-22</link>
            <description><![CDATA[ <pre class="bbcode">
SELECT  price.col1 AS col1 ,
|       price.col2 AS col2 ,
|       price.col3 AS col3
FROM
|       (SELECT price.col1 AS col1 ,
|       |       price.col2 AS col2 ,
|       |       price.col3 AS col3
|       FROM
|       |       (SELECT price.col1 AS col1 ,
|       |       |       price.col2 AS col2 ,
|       |       |       price.col3 AS col3
|       |       FROM
|       |       |       (SELECT price.col1 AS col1 ,
|       |       |       |       price.col2 AS col2 ,
|       |       |       |       price.col3 AS col3
|       |       |       FROM (SELECTprice.col1 AS col1 , price.col2 AS col2 , price.col3 AS col3 FROM
|       |       |       |       (SELECT price.col1 AS col1 ,
|       |       |       |       |       price.col2 AS col2 ,
|       |       |       |       |       price.col3 AS col3
|       |       |       |       FROM
|       |       |       |       |       (SELECT tv.column1,
|       |       |       |       |       |       tv.column2,
|       |       |       |       |       |       MAX (digits(tv.column3) concat digits(tv.column4) ) AS librarymax
|       |       |       |       |       FROM    db1.v_table1 tv
|       |       |       |       |       WHERE   tv.column1 &lt;&gt; 'Y'
|       |       |       |       |       |   AND tv.column1 IN ( 'a'  ,
|       |       |       |       |       |       |       |       '1'  ,
|       |       |       |       |       |       |       |       '12' ,
|       |       |       |       |       |       |       |       'b'  ,
|       |       |       |       |       |       |       |       'c' )
|       |       |       |       |       |   AND tv.column2 &gt;= DATE(tv.column4)
|       |       |       |       |       |   AND tv.column3  &lt; DATE(tv.column15)
|       |       |       |       |       GROUP BY tv.column1,
|       |       |       |       |       |       tv.column2
|       |       |       |       |       ) AS libraryprod,
|       |       |       |       |       db1.table2 th
|       |       |       |       WHERE   th.column1 = libraryprod.column1
|       |       |       |       |   AND th.column2 = libraryprod.column2
|       |       |       |       ) AS alllibrarysales GROUP BY alllibrarysales.column1, alllibrarysales.column2 ) AS onelibrarysales
|       |       |       ) AS library
|       |       |       LEFT OUTER JOIN db1.v_table3 librarystat
|       |       |       ON      librarystat.column1 = library.column1
|       |       |       |   AND librarystat.column2 = library.column2
|       |       |       |    OR
|       |       |       |       (
|       |       |       |       |       librarystat.column4 = library.column4
|       |       |       |       |   AND librarystat.column5 = library.column5
|       |       |       |       )
|       |       |       |   AND
|       |       |       |       (
|       |       |       |       |       librarystat.column5 = 'I'
|       |       |       |       |    OR librarystat.column4 = 'Gold'
|       |       |       |       |    OR librarystat.column5 = 'Bold'
|       |       |       |       )
|       |       |       |   AND librarystat.column6 &lt;= 'Z74'
|       |       ) AS x
|       ) AS price
WHERE   price.column1 &lt; 'R45'
|    OR
|       (
|       |       price.column2 = 'R46' *
|       |   AND price.column3 = 6
|       )
GROUP BY price.column1,
|       price.column2 ,
|       price.column3
</pre>]]></description>
            <dc:creator>guidomarcel</dc:creator>
            <category>Examples</category>
            <pubDate>Thu, 10 Jan 2013 17:51:42 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.sqlinform.com/forum4/read.php?4,19,19#msg-19</guid>
            <title>No Linebreak for small SQL (1 reply)</title>
            <link>http://www.sqlinform.com/forum4/read.php?4,19,19#msg-19</link>
            <description><![CDATA[ <b><u><span style="color:#CC0033">No Linebreak for small SQL &lt; 10 chars</span></u></b><br />
<br />
<pre class="bbcode">
IF credit &gt;= debit THEN
        UPDATE customeraccount
        SET    balance    = balance - debit_amount
        WHERE  account_id = 100400;

ELSE
        UPDATE customeraccount
        SET    balance    = balance + debit_amount
        WHERE  account_id = 100400;
END;</pre>
<br />
<b><u><span style="color:#CC0033">No Linebreak for small SQL &lt; 100 chars</span></u></b><br />
<pre class="bbcode">
IF credit &gt;= debit THEN
        UPDATE customeraccount SET balance = balance - debit_amount WHERE account_id = 100400;

ELSE
        UPDATE customeraccount SET balance = balance + debit_amount WHERE account_id = 100400;

END;
</pre>]]></description>
            <dc:creator>guidomarcel</dc:creator>
            <category>Examples</category>
            <pubDate>Tue, 04 Jan 2011 08:55:00 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.sqlinform.com/forum4/read.php?4,18,18#msg-18</guid>
            <title>&quot;Keep 1st line initial indentation&quot; (no replies)</title>
            <link>http://www.sqlinform.com/forum4/read.php?4,18,18#msg-18</link>
            <description><![CDATA[ <u><b><span style="color:#CC0033">Before Formatting</span></b></u> <br />
<br />
<pre class="bbcode">
                        SELECT  price.col1 AS col1, price.col2 AS col2 , price.col3 AS col3, max(price.col4) AS col4, max(price.col5) AS col5, max(price.col6) AS col6, max(price.col7) AS col7 FROM    table_1 t1, table_2 t2 WHERE   col1 = col2 AND column_1 = small_column AND column_3411 &lt;= column_12_sup and col1 = 'Test Run' AND column_4532 = c1.dert</pre>
<br />
<u><b><span style="color:#CC0033">After Formatting</span></b></u> <br />
The number of blanks from the 1st line are kept.<br />
<pre class="bbcode">
                        SELECT price.col1         AS col1 ,
                               price.col2         AS col2 ,
                               price.col3         AS col3 ,
                               MAX ( price.col4 ) AS col4 ,
                               MAX ( price.col5 ) AS col5 ,
                               MAX ( price.col6 ) AS col6 ,
                               MAX ( price.col7 ) AS col7
                        FROM   table_1 t1,
                               table_2 t2
                        WHERE  col1         = col2
                           AND column_1     = small_column
                           AND column_3411 &lt;= column_12_sup
                           AND col1         = 'Test Run'
                           AND column_4532  = c1.dert
</pre>]]></description>
            <dc:creator>guidomarcel</dc:creator>
            <category>Examples</category>
            <pubDate>Mon, 30 Mar 2009 16:48:58 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.sqlinform.com/forum4/read.php?4,17,17#msg-17</guid>
            <title>&quot;Indent Lines beginning with AND / OR&quot; (no replies)</title>
            <link>http://www.sqlinform.com/forum4/read.php?4,17,17#msg-17</link>
            <description><![CDATA[ <b><u><span style="color:#CC0033">Indent Lines beginning with AND / OR</span></u></b><br />
<pre class="bbcode">
 SELECT price.col1         AS col1 ,
        price.col2         AS col2 ,
        price.col3         AS col3 ,
        MAX ( price.col4 ) AS col4 ,
        MAX ( price.col5 ) AS col5 ,
        MAX ( price.col6 ) AS col6 ,
        MAX ( price.col7 ) AS col7
   FROM table_1 t1 ,
        table_2 t2
  WHERE col1                    = col2
        AND column_1            = small_column
        AND column_3411        &lt;= column_12_sup
        AND col1                = 'Test Run'
        AND column_4532         = c1.dert
        AND librarystat.column2 = library.column2
        OR
        (
                librarystat.column4     = library.column4
                AND librarystat.column5 = library.column5
        )
        AND
        (
                librarystat.column5    = 'I'
                OR librarystat.column4 = 'Gold'
                OR librarystat.column5 = 'Bold'
        )
        AND librarystat.column6 &lt;= 'Z74'</pre>
<br />
<br />
<b><u><span style="color:#CC0033">Do NOT Indent Lines beginning with AND / OR</span></u></b><br />
<pre class="bbcode">
 SELECT price.col1         AS col1 ,
        price.col2         AS col2 ,
        price.col3         AS col3 ,
        MAX ( price.col4 ) AS col4 ,
        MAX ( price.col5 ) AS col5 ,
        MAX ( price.col6 ) AS col6 ,
        MAX ( price.col7 ) AS col7
   FROM table_1 t1 ,
        table_2 t2
  WHERE col1                = col2
    AND column_1            = small_column
    AND column_3411        &lt;= column_12_sup
    AND col1                = 'Test Run'
    AND column_4532         = c1.dert
    AND librarystat.column2 = library.column2
     OR
        (
                librarystat.column4 = library.column4
            AND librarystat.column5 = library.column5
        )
    AND
        (
                librarystat.column5 = 'I'
             OR librarystat.column4 = 'Gold'
             OR librarystat.column5 = 'Bold'
        )
    AND librarystat.column6 &lt;= 'Z74'

</pre>]]></description>
            <dc:creator>guidomarcel</dc:creator>
            <category>Examples</category>
            <pubDate>Mon, 30 Mar 2009 15:38:12 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.sqlinform.com/forum4/read.php?4,16,16#msg-16</guid>
            <title>Number of &quot;identifiers per line&quot; (2 replies)</title>
            <link>http://www.sqlinform.com/forum4/read.php?4,16,16#msg-16</link>
            <description><![CDATA[ <b><span style="color:#CC0033"><u>SQL with 4 identifiers per line</u></span></b><br />
<pre class="bbcode">
 SELECT col1          , col2          , col3          , col4          ,
        col5          , col6          , col7          , tablecolumn8  ,
        tablecolumn9  , tablecolumn10 , tablecolumn11 , tablecolumn12 ,
        tablecolumn13 , tablecolumn14 , tablecolumn15 , tablecolumn16 ,
        tablecolumn17 , tablecolumn18 , tablecolumn19 , tablecolumn20 ,
        tablecolumn21 , tablecolumn22 , tablecolumn23 , tablecolumn24 ,
        tablecolumn25 , tablecolumn26 , tablecolumn27 , tablecolumn28 ,
        tablecolumn29 , tablecolumn30
 FROM   foo</pre>
<br />
<b><span style="color:#CC0033"><u>Same SQL with 1 identifier per line</u></span></b><br />
<pre class="bbcode">
 SELECT col1          ,
        col2          ,
        col3          ,
        col4          ,
        col5          ,
        col6          ,
        col7          ,
        tablecolumn8  ,
        tablecolumn9  ,
        tablecolumn10 ,
        tablecolumn11 ,
        tablecolumn12 ,
        tablecolumn13 ,
        tablecolumn14 ,
        tablecolumn15 ,
        tablecolumn16 ,
        tablecolumn17 ,
        tablecolumn18 ,
        tablecolumn19 ,
        tablecolumn20 ,
        tablecolumn21 ,
        tablecolumn22 ,
        tablecolumn23 ,
        tablecolumn24 ,
        tablecolumn25 ,
        tablecolumn26 ,
        tablecolumn27 ,
        tablecolumn28 ,
        tablecolumn29 ,
        tablecolumn30
 FROM   foo
</pre>]]></description>
            <dc:creator>guidomarcel</dc:creator>
            <category>Examples</category>
            <pubDate>Fri, 26 Oct 2012 13:58:25 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.sqlinform.com/forum4/read.php?4,9,9#msg-9</guid>
            <title>&quot;Show Pseudo-Code&quot; (no replies)</title>
            <link>http://www.sqlinform.com/forum4/read.php?4,9,9#msg-9</link>
            <description><![CDATA[ <b><u><span style="color:#CC0033">With "Show Pseudo-Code"</span></u></b><br />
<br />
<pre class="bbcode">
SELECT price.col1 AS ...
FROM   table_1 t1 ...
WHERE  col1 = ...

UNION

SELECT   price.col1 AS ...
FROM
         (SELECT store.column1 ...
         FROM
                 (SELECT library.column1 ...
                 FROM
                         (SELECT INTEGER ...
                         FROM
                                 (SELECT  alllibrarysales.column1 ...
                                 FROM
                                          (SELECT libraryprod.column1 ...
                                          FROM
                                                  (SELECT  tv.column1 ...
                                                  FROM     db1.v_table1 tv ...
                                                  WHERE    tv.column1 &lt;&gt; ...
                                                  GROUP BY tv.column1 , ...
                                                  ) AS libraryprod ...
                                          WHERE   th.column1 = ...
                                          ) AS alllibrarysales ...
                                 GROUP BY alllibrarysales.column1 , ...
                                 ) AS onelibrarysales ...
                         ) AS library ...
                         LEFT OUTER JOIN db1.v_table3 librarystat ...
                 ) AS x ...
         ) AS price ...
WHERE    price.column1 &lt; ...
GROUP BY price.column1 , ...</pre>
<br />
<b><u><span style="color:#CC0033">Without "Show Pseudo-Code"</span></u></b><br />
<pre class="bbcode">
SELECT price.col1       AS col1
     , price.col2       AS col2
     , price.col3       AS col3
     , MAX (price.col4) AS col4
     , MAX (price.col5) AS col5
     , MAX (price.col6) AS col6
     , MAX (price.col7) AS col7
FROM   table_1 t1
     , table_2 t2
WHERE  col1         = col2
   AND column_1     = small_column
   AND column_3411 &lt;= column_12_sup
   AND col1         = 'Test Run'
   AND column_4532  = c1.dert

UNION

SELECT   price.col1       AS col1
       , price.col2       AS col2
       , price.col3       AS col3
       , MAX (price.col4) AS col4
       , MAX (price.col5) AS col5
       , MAX (price.col6) AS col6
       , MAX (price.col7) AS col7
FROM
         (SELECT store.column1
               , CAST (store.column2 AS INTEGER) AS column2
               , store.columnwe34r3              AS column3
               , store.column4_prod              AS column4
               , store.column5_pre_prod_first    AS column5
               , SUBSTR (store.column6,11,1)     AS column6
               , store.column7                   AS column7
         FROM
                 (SELECT library.column1
                       , library.column2
                       , library.column3
                       , CASE library.column4
                                 WHEN cheap
                                 THEN digits (library.column27) concat library.column28
                                 ELSE 123456
                         END AS column4
                       , CASE library.column5
                                 WHEN expensive
                                 THEN digits (library.column27) concat library.column28
                                 ELSE 123456
                         END AS library.column6
                       , CASE column7
                                 WHEN free
                                 THEN digits (library.column27) concat library.column28
                                 ELSE 123456
                         END AS column7
                       ,
                 FROM
                         (SELECT INTEGER (SUBSTR (onelibrarysales.column1,11,10)) AS column1
                               , SUBSTR (onelibrarysales.column2,21,10)           AS column2
                               , onelibrarysales.column3
                               , onelibrarysales.column4
                               , SUBSTR (onelibrarysales.column5,31,6) AS column5
                               , SUBSTR (onelibrarysales.column6,37,2) AS column6
                               , SUBSTR (onelibrarysales.column7,39,6) AS column7
                               ,
                         FROM
                                 (SELECT  alllibrarysales.column1
                                        , alllibrarysales.column2
                                        , MAX (alllibrarysales.column3)                                                                                                                               AS alllibrarysales.column3
                                        , MAX (CHAR (alllibrarysales.column4,iso) concat CHAR (alllibrarysales.column5,iso) concat digits (alllibrarysales.column6) concat (alllibrarysales.column7)) AS column5
                                 FROM
                                          (SELECT libraryprod.column1
                                                , libraryprod.column2
                                                , libraryprod.column3
                                                , libraryprod.column4
                                                , libraryprod.column5
                                                , libraryprod.column6
                                                , libraryprod.column7
                                          FROM
                                                  (SELECT  tv.column1
                                                         , tv.column2
                                                         , MAX (digits (tv.column3) concat digits (tv.column4)) AS librarymax
                                                  FROM     db1.v_table1 tv
                                                  WHERE    tv.column1 &lt;&gt; 'Y'
                                                       AND tv.column1 IN ('a'
                                                                        , '1'
                                                                        , '12'
                                                                        , '123'
                                                                        , ' 1234'
                                                                        , '12345'
                                                                        , '123456'
                                                                        , '1234567'
                                                                        , '12345678'
                                                                        , '123456789'
                                                                        , '1234567890'
                                                                        , '1 12 123 1234 12345 123456 1234567 12345678'
                                                                        , 'b'
                                                                        , 'c')
                                                       AND tv.column2 &gt;= DATE (tv.column4)
                                                       AND tv.column3  &lt; DATE (tv.column15)
                                                  GROUP BY tv.column1
                                                         , tv.column2
                                                  ) AS libraryprod
                                                , db1.table2 th
                                          WHERE   th.column1 = libraryprod.column1
                                              AND th.column2 = libraryprod.column2
                                          ) AS alllibrarysales
                                 GROUP BY alllibrarysales.column1
                                        , alllibrarysales.column2
                                 ) AS onelibrarysales
                         ) AS library
                         LEFT OUTER JOIN db1.v_table3 librarystat
                         ON      librarystat.column1 = library.column1
                             AND librarystat.column2 = library.column2
                              OR
                                 (
                                         librarystat.column4 = library.column4
                                     AND librarystat.column5 = library.column5
                                 )
                             AND
                                 (
                                         librarystat.column5 = 'I'
                                      OR librarystat.column4 = 'Gold'
                                      OR librarystat.column5 = 'Bold'
                                 )
                             AND librarystat.column6 &lt;= 'Z74'
                 ) AS x
         ) AS price
WHERE    price.column1 &lt; 'R45'
      OR
         (
                  price.column2 = 'R46'
              AND price.column3 = 6
         )
GROUP BY price.column1
       , price.column2
       , price.column3
       , price.column4
       , price.column5
       , price.column6
       , price.column7
</pre>]]></description>
            <dc:creator>guidomarcel</dc:creator>
            <category>Examples</category>
            <pubDate>Wed, 11 Mar 2009 08:41:46 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.sqlinform.com/forum4/read.php?4,8,8#msg-8</guid>
            <title>&quot;comma before&quot; and &quot;comma affter&quot; (no replies)</title>
            <link>http://www.sqlinform.com/forum4/read.php?4,8,8#msg-8</link>
            <description><![CDATA[ <span style="color:#CC0033"><b><u>Linebreak after comma</u></b></span><br />
<pre class="bbcode">
SELECT price.col1       AS col1 ,
       price.col2       AS col2 ,
       price.col3       AS col3 ,
       MAX (price.col4) AS col4 ,
       MAX (price.col5) AS col5 ,
       MAX (price.col6) AS col6 ,
       MAX (price.col7) AS col7</pre>
<br />
<br />
<span style="color:#CC0033"><b><u>Linebreak before comma</u></b></span><br />
<pre class="bbcode">
SELECT price.col1       AS col1
     , price.col2       AS col2
     , price.col3       AS col3
     , MAX (price.col4) AS col4
     , MAX (price.col5) AS col5
     , MAX (price.col6) AS col6
     , MAX (price.col7) AS col7
</pre>]]></description>
            <dc:creator>guidomarcel</dc:creator>
            <category>Examples</category>
            <pubDate>Wed, 11 Mar 2009 08:37:11 +0100</pubDate>
        </item>
    </channel>
</rss>
