Folding behavior of SQL code
-
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 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
-