Navigation

    Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Folding behavior of SQL code

    Help wanted · · · – – – · · ·
    collapse sql sql formatter fold
    1
    2
    1525
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jjacobs13
      jjacobs13 last edited by jjacobs13

      I have noticed behavior regarding folding of SQL code in Notepad++ that is unexpected to me, and I would be grateful for any guidance regarding why.

      Using the following SQL code:

      select colName
      , case when colName2 = ‘2.2’
      then 1
      end as varName
      from schemaName.tableName
      where 1=1
      ;

      Notepad++ folds everything from the CASE statement to the end (semicolon) of the SQL statement. The desired folding is the code from CASE to END AS varName.

      The following changes cause the folding behavior to act as desired (i.e. only code from the CASE to the END lines are folded together):

      • The WHEN is moved to the next line, or
      • The THEN is moved to the same line as the CASE and WHEN.

      However, these solutions require changes to the formatting of the actual code, which is undesirable. The preferred solution involves leaving the code as formatted (e.g. revising the language folding specification). If anyone has useful tips to fold the CASE statement as desired (other than the code-formatting solutions identified above), I would be appreciative.

      Also, if this is considered a “bug” or “unexpected behavior” by others, it would be nice to know.

      jjacobs13 1 Reply Last reply Reply Quote 0
      • jjacobs13
        jjacobs13 @jjacobs13 last edited by

        @jjacobs13 A quick clarification: the desired folding occurs when either

        • The CASE, WHEN, and THEN keywords are on the same line, or
        • The WHEN is moved to a line (whether on the same as the THEN or on a different line) after the CASE line
        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Copyright © 2014 NodeBB Forums | Contributors