Skip to content

Common table expression

Tako Lee edited this page Mar 7, 2014 · 5 revisions
  • AS keyword in the same line with WITH keyword

    Option: fmt082_cte_as_in_newline = false, type: TFmtBoolean.

    WITH mycte(x) AS (SELECT x = Convert( VARCHAR(1000), 'hello' ) 
                      UNION ALL  
                      SELECT Convert( VARCHAR(1000), x + 'a' )  
                      FROM   mycte  
                      WHERE  Len( x ) < 10 
                      UNION ALL  
                      SELECT Convert( VARCHAR(1000), x + 'b' )  
                      FROM   mycte  
                      WHERE  Len( x ) < 10) 
    SELECT x  
    FROM   mycte  
    ORDER  BY Len( x ), 
              x;  
  • AS keyword in new line

    Option: fmt082_cte_as_in_newline = false, type: TFmtBoolean.

    Option: fmt083_cte_as_indent = n, type: int.

    WITH mycte(x) 
         AS (SELECT x = Convert( VARCHAR(1000), 'hello' ) 
             UNION ALL  
             SELECT Convert( VARCHAR(1000), x + 'a' )  
             FROM   mycte  
             WHERE  Len( x ) < 10 
             UNION ALL  
             SELECT Convert( VARCHAR(1000), x + 'b' )  
             FROM   mycte  
             WHERE  Len( x ) < 10) 
    SELECT x  
    FROM   mycte  
    ORDER  BY Len( x ), 
              x;  

Clone this wiki locally