Community
    • Login

    Folding behavior of SQL code

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    collapsesqlsql formatterfold
    2 Posts 1 Posters 2.4k Views
    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.
    • jjacobs13J
      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.

      jjacobs13J 1 Reply Last reply Reply Quote 0
      • jjacobs13J
        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
        • dfs-D dfs- referenced this topic on
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors