General SQL Parser and SQL Pretty Printer Formatter options

Index

Available format options for subquery:

Subquery_Newline_After_IN Type: boolean Default: false
Subquery_Newline_After_EXISTS Type: boolean Default: false
Subquery_Newline_After_ComparisonOperator Type: boolean Default: false
Subquery_Newline_Before_ComparisonOperator Type: boolean Default: false

Example format options:

NameValue
Subquery_Newline_After_INfalse

Formatted SQL:

SELECT [Northwind].[dbo].[Order Details].[Discount],
       [Northwind].[dbo].[Order Details].[OrderID]   AS [OrderId],
       [Northwind].[dbo].[Order Details].[ProductID] AS [ProductId],
       [Northwind].[dbo].[Order Details].[Quantity],
       [Northwind].[dbo].[Order Details].[UnitPrice]
FROM   [Northwind].[dbo].[Order Details]
WHERE  ( [Northwind].[dbo].[Order Details].[OrderID] IN (SELECT [Northwind].[dbo].[Orders].[OrderID] AS [OrderId]
                                                         FROM   [Northwind].[dbo].[Orders]
                                                         WHERE  (( [Northwind].[dbo].[Orders].[CustomerID] IN (SELECT [Northwind].[dbo].[Customers].[CustomerID] AS [CustomerId]
                                                                                                               FROM   [Northwind].[dbo].[Customers]) ))) ) 


NameValue
Subquery_Newline_After_INtrue

Formatted SQL: the following query is not so wide as previous one.

SELECT [Northwind].[dbo].[Order Details].[Discount],
       [Northwind].[dbo].[Order Details].[OrderID]   AS [OrderId],
       [Northwind].[dbo].[Order Details].[ProductID] AS [ProductId],
       [Northwind].[dbo].[Order Details].[Quantity],
       [Northwind].[dbo].[Order Details].[UnitPrice]
FROM   [Northwind].[dbo].[Order Details]
WHERE  ( [Northwind].[dbo].[Order Details].[OrderID] IN
         (SELECT [Northwind].[dbo].[Orders].[OrderID] AS [OrderId]
          FROM   [Northwind].[dbo].[Orders]
          WHERE  (( [Northwind].[dbo].[Orders].[CustomerID] IN
                    (SELECT [Northwind].[dbo].[Customers].[CustomerID] AS [CustomerId]
                     FROM   [Northwind].[dbo].[Customers]) ))) ) 

Example format options:

NameValue
Subquery_Newline_After_EXISTSfalse

Formatted SQL:

SELECT TOP 1 CASE
               WHEN CASE
                      WHEN NOT EXISTS (SELECT [LPA_L1].[CategoryId]
                                       FROM   (SELECT [Northwind].[dbo].[Products].[CategoryID] AS [CategoryId],
                                                      [Northwind].[dbo].[Products].[Discontinued],
                                                      [Northwind].[dbo].[Products].[ProductID]  AS [ProductId],
                                                      [Northwind].[dbo].[Products].[ProductName],
                                                      [Northwind].[dbo].[Products].[QuantityPerUnit],
                                                      [Northwind].[dbo].[Products].[ReorderLevel],
                                                      [Northwind].[dbo].[Products].[SupplierID] AS [SupplierId],
                                                      [Northwind].[dbo].[Products].[UnitPrice],
                                                      [Northwind].[dbo].[Products].[UnitsInStock],
                                                      [Northwind].[dbo].[Products].[UnitsOnOrder]
                                               FROM   [Northwind].[dbo].[Products]
                                               WHERE  (( [Northwind].[dbo].[Products].[CategoryID] = @p1 ))) [LPA_L1]) THEN 1
                      ELSE 0
                    END = 1 THEN @p3
               ELSE @p5
             END AS [LLBLV_1]
FROM   [Northwind].[dbo].[Products]; 


NameValue
Subquery_Newline_After_EXISTStrue

Formatted SQL: the following query is not so wide as previous one.

SELECT TOP 1 CASE
               WHEN CASE
                      WHEN NOT EXISTS
                               (SELECT [LPA_L1].[CategoryId]
                                FROM   (SELECT [Northwind].[dbo].[Products].[CategoryID] AS [CategoryId],
                                               [Northwind].[dbo].[Products].[Discontinued],
                                               [Northwind].[dbo].[Products].[ProductID]  AS [ProductId],
                                               [Northwind].[dbo].[Products].[ProductName],
                                               [Northwind].[dbo].[Products].[QuantityPerUnit],
                                               [Northwind].[dbo].[Products].[ReorderLevel],
                                               [Northwind].[dbo].[Products].[SupplierID] AS [SupplierId],
                                               [Northwind].[dbo].[Products].[UnitPrice],
                                               [Northwind].[dbo].[Products].[UnitsInStock],
                                               [Northwind].[dbo].[Products].[UnitsOnOrder]
                                        FROM   [Northwind].[dbo].[Products]
                                        WHERE  (( [Northwind].[dbo].[Products].[CategoryID] = @p1 ))) [LPA_L1]) THEN 1
                      ELSE 0
                    END = 1 THEN @p3
               ELSE @p5
             END AS [LLBLV_1]
FROM   [Northwind].[dbo].[Products]; 

Example format options:

NameValue
Subquery_Newline_After_ComparisonOperatorfalse

Formatted SQL:

SELECT *
FROM   t
WHERE  SomeField = (SELECT TOP 1 Blah
                    FROM   t1
                    ORDER  BY f) 


NameValue
Subquery_Newline_After_ComparisonOperatortrue

Formatted SQL: the following query is not so wide as previous one.

SELECT *
FROM   t
WHERE  SomeField =
       (SELECT TOP 1 Blah
        FROM   t1
        ORDER  BY f) 

Example format options:

NameValue
Subquery_Newline_Before_ComparisonOperatorfalse

Formatted SQL:

SELECT [Northwind].[dbo].[Categories].[CategoryID] AS [CategoryId],
       [Northwind].[dbo].[Categories].[CategoryName],
       [Northwind].[dbo].[Categories].[Description],
       [Northwind].[dbo].[Categories].[Picture]
FROM   [Northwind].[dbo].[Categories]
WHERE  (((( (SELECT Sum([LPA_L1].[UnitsInStock]) AS [LPAV_]
             FROM   (SELECT [Northwind].[dbo].[Products].[CategoryID] AS [CategoryId],
                            [Northwind].[dbo].[Products].[Discontinued],
                            [Northwind].[dbo].[Products].[ProductID]  AS [ProductId],
                            [Northwind].[dbo].[Products].[ProductName],
                            [Northwind].[dbo].[Products].[QuantityPerUnit],
                            [Northwind].[dbo].[Products].[ReorderLevel],
                            [Northwind].[dbo].[Products].[SupplierID] AS [SupplierId],
                            [Northwind].[dbo].[Products].[UnitPrice],
                            [Northwind].[dbo].[Products].[UnitsInStock],
                            [Northwind].[dbo].[Products].[UnitsOnOrder]
                     FROM   [Northwind].[dbo].[Products]
                     WHERE  (( [Products].[CategoryID] = [Categories].[CategoryID] ))) [LPA_L1]) > @p2 )))) 


NameValue
Subquery_Newline_Before_ComparisonOperatortrue

Formatted SQL: have the '> @p2' on another line so it's easier to see that the left operand is the complete scalar and it doesn't secretly belong to the WHERE of the scalar.

SELECT [Northwind].[dbo].[Categories].[CategoryID] AS [CategoryId],
       [Northwind].[dbo].[Categories].[CategoryName],
       [Northwind].[dbo].[Categories].[Description],
       [Northwind].[dbo].[Categories].[Picture]
FROM   [Northwind].[dbo].[Categories]
WHERE  (((( (SELECT Sum([LPA_L1].[UnitsInStock]) AS [LPAV_]
             FROM   (SELECT [Northwind].[dbo].[Products].[CategoryID] AS [CategoryId],
                            [Northwind].[dbo].[Products].[Discontinued],
                            [Northwind].[dbo].[Products].[ProductID]  AS [ProductId],
                            [Northwind].[dbo].[Products].[ProductName],
                            [Northwind].[dbo].[Products].[QuantityPerUnit],
                            [Northwind].[dbo].[Products].[ReorderLevel],
                            [Northwind].[dbo].[Products].[SupplierID] AS [SupplierId],
                            [Northwind].[dbo].[Products].[UnitPrice],
                            [Northwind].[dbo].[Products].[UnitsInStock],
                            [Northwind].[dbo].[Products].[UnitsOnOrder]
                     FROM   [Northwind].[dbo].[Products]
                     WHERE  (( [Products].[CategoryID] = [Categories].[CategoryID] ))) [LPA_L1])
             > @p2 ))))