Einzelnen Beitrag anzeigen

guidomarcel

Registriert seit: 25. Nov 2006
2 Beiträge
 
#20

Re: Source Code Formatter für SQL gesucht

  Alt 26. Nov 2006, 21:07
Zitat:
Dann möchte ich mal meinen Wunschzettel abgeben
Hallo Jens,
vielen Dank für die Beispiele. Ich werde mal versuchen, diese Regeln einzubauen. Die SQL Statements müßten teilweise schon so formatiert werden, wie Du das vorschlägst, aber bei den Stored Procedures hapert es noch, da ich mich bisher auf ORACLE und DB2 konzentriert habe.

SQL-Code:
------------------------------------------
-- This is an example SQL
------------------------------------------
 SELECT price.c1 AS c1,
        price.c2 AS c2 ,
        price.c3 AS c3,
        max(price.c4) AS c4,
        max(price.c5) AS c5,
        max(price.c6) AS c6,
        max(price.c7) AS c7
   FROM table_1 t1,
        table_2 t2
  WHERE c1 = c2
    AND c_1 = small_c
    AND c_3411 <= c_12_sup
    AND c1 = 'Test Run
    AND c_4532 = c1.dert
  UNION
 SELECT price.c1 AS c1,
        price.c2 AS c2 ,
        price.c3 AS c3,
        max(price.c4) AS c4,
        max(price.c5) AS c5,
        max(price.c6) AS c6,
        /*******************   
        * This is a block  *   
        * comment within a *   
        * SQL statement    *   
        *******************/
 
        max(price.c7) AS c7
   FROM
        (SELECT store.c1,
                cast (store.c2 AS integer) AS c2, -- inline comment
                store.cwe34r3 AS c3, -- inline comment
                store.c4_prod AS c4, -- inline comment
                store.c5_pre_prod_first AS c5 , -- inline comment
                substr(store.c6,11,1) AS c6, -- inline comment
                store.c7 AS c7 -- inline comment
           FROM
                (SELECT lib.c1,
                        ---------------------
                        -- This is a line --
                        -- comment in a --
                        -- SQL statement --
                        ---------------------
                        lib.c2,
                        lib.c3 -- inline comment
                        ,
                        CASE lib.c4
                                WHEN cheap
                                THEN digits(lib.c27) concat lib.c28
                                ELSE 123456
                        END AS c4,
                        CASE lib.c5
                                WHEN expensive
                                THEN digits(lib.c27) concat lib.c28
                                ELSE 123456
                        END AS lib.c6,
                        CASE c7
                                WHEN free
                                THEN digits(lib.c27) concat lib.c28
                                ELSE 123456
                        END AS c7,
                   FROM
                        (SELECT integer(substr(onelibsales.c1,11,10)) AS c1,
                                substr(onelibsales.c2,21,10) AS c2 ,
                                onelibsales.c3,
                                onelibsales.c4,
                                substr(onelibsales.c5,31,6) AS c5,
                                substr(onelibsales.c6,37,2) AS c6,
                                substr(onelibsales.c7,39,6) AS c7,
                           FROM
                                (SELECT libs.c1,
                                        libs.c2,
                                        max(libs.c3) AS libs.c3 ,
                                        max(char(libs.c4,iso) ) AS c5
                                   FROM
                                        (SELECT tv.c1,
                                                tv.c2,
                                                max(digits(tv.c3)) AS libmax
                                           FROM db1.v_table1 tv
                                          WHERE tv.c1 <> 'Y
                                            AND tv.c1 in ( 'a' , '1' , '12' )
                                            AND tv.c2 >= date(tv.c4)
                                            AND tv.c3 < date(tv.c15)
                                       GROUP BY tv.c1,
                                                tv.c2
                                        ) AS libprod,
                                        db1.table2 th
                               GROUP BY libs.c1,
                                        libs.c2
                                ) AS onelibsales
                        ) AS lib
                LEFT OUTER JOIN db1.v_table3 libstat
                     ON libstat.c1 = lib.c1
                    AND libstat.c2 = lib.c2
                     OR ( libstat.c4 = lib.c4
                    AND libstat.c5 = lib.c5 )
                        /*******************
                        * This is a block  *
                        * comment within a *
                        * SQL statement    *
                        *******************/
 
                    AND ( libstat.c5 = 'I
                     OR libstat.c4 = 'Gold
                     OR libstat.c5 = 'Bold' )
                    AND libstat.c6 <= 'Z74
                ) AS x
        ) AS price
  WHERE price.c1 < 'R45
     OR ( price.c2= 'R46
        /******************* 
        * This is a block  * 
        * comment within a * 
        * SQL statement    * 
        *******************/
 
    AND price.c3 = 6 )
GROUP BY price.c1,
        price.c2,
        /******************* 
        * This is a block  * 
        * comment within a * 
        * SQL statement    * 
        *******************/
 
        price.c3,
        price.c4,
        price.c5,
        price.c6,
        price.c7

Grüße
GuidoMarcel
  Mit Zitat antworten Zitat