SQL Formatter Options

CASE

The CASE Options in the SQL Formatter Tool allow you to format CASE statements with precision, ensuring better readability and alignment with coding standards. These settings control indentation, line breaks, and compactness for both simple and complex CASE structures.

Sql Formatter Options Case

CASE Formatting

  1. CASE, WHEN, THEN, ELSE, END

    • Adds line breaks before these keywords in the CASE statement for better clarity and structure.
    • These options ensure each component of the CASE block is properly separated.
  2. Indent CASE inside „()“

    • Indents the entire CASE block when it is enclosed within parentheses.
  3. Indent WHEN, THEN, ELSE

    • Adds indentation to the WHEN, THEN, and ELSE keywords for hierarchical alignment in nested or multi-line CASE statements.

CASE Condition

  1. AND/OR

    • Adds a line break before logical operators (AND, OR) within the CASE conditions to clearly separate them from other conditions.
  2. Open „(“ / Close „)“

    • Open „(„: Adds a line break before the opening parenthesis in CASE conditions.
    • Close „)“: Adds a line break after the closing parenthesis for better visibility of nested conditions.

Small CASE Statements on 1 Line

  1. No Break for CASE < X chars
    • Keeps small CASE statements (e.g., under 10 characters) on a single line for compactness.
    • Adjust the character limit using the -10 and +10 buttons to define what qualifies as a „small“ CASE statement.
Sql Formatting For Small Case Sttatements

Compact vs. Expand

  • Compact: Condenses CASE statements by reducing line breaks and indentation.
  • Expand: Formats CASE statements with more line breaks and indentation for improved readability.

How to Use These Settings

  1. Enable or Disable Line Breaks

    • Use the checkboxes for CASE, WHEN, THEN, ELSE, END to specify where line breaks should be added in CASE blocks.
  2. Customize Indentation

    • Enable indentation options like Indent CASE inside „()“ and Indent WHEN, THEN, ELSE to align keywords hierarchically within the CASE block.
  3. Adjust Logical Conditions

    • Use the AND/OR option to structure complex conditions within CASE statements with line breaks and proper alignment.
  4. Set Character Limits for Compactness

    • Define a character limit for keeping small CASE statements on one line to maintain a balance between compactness and readability.
  5. Switch Between Compact and Expand Modes

    • Use Compact for minimizing line breaks in short CASE blocks and Expand for a detailed, well-structured format.