I usually read the sql tag here on Stack Overflow and sometimes in the questions there are long queries with very little code on every single line, for example this question.
The particular point is the second code block:
...
SELECT C.KeyCompany ,
CASE WHEN ( GROUPING(O.O1) = 1 ) THEN ''
ELSE O.O1
END AS O1 ,
NULL AS O2 ,
NULL AS O3 ,
NULL AS O4 ,
NULL AS O5 ,
NULL AS O6 ,
NULL AS O7 ,
NULL AS O8 ,
NULL AS O9 ,
NULL AS O10 ,
NULL AS O11 ,
NULL AS O12 ,
1 AS viewDepth
FROM dbo.COMPANY C
INNER JOIN dbo.SUBCOMPANY SC ON SC.KeyCompany = C.KeyCompany
AND ( C.viewdepth + 1 ) = 1
INNER JOIN dbo.Organistation O ON O.KeySubCompany = SC.KeySubCompany
GROUP BY C.KeyCompany ,
O.O1
WITH ROLLUP
...
I thought about edit it to something like
...
SELECT C.KeyCompany ,
CASE WHEN ( GROUPING(O.O1) = 1 ) THEN ''
ELSE O.O1
END AS O1 ,
NULL AS O2, NULL AS O3, NULL AS O4, NULL AS O5, NULL AS O6, NULL AS O7,
NULL AS O8, NULL AS O9, NULL AS O10, NULL AS O11, NULL AS O12,
1 AS viewDepth
FROM dbo.COMPANY C
INNER JOIN dbo.SUBCOMPANY SC ON SC.KeyCompany = C.KeyCompany
AND ( C.viewdepth + 1 ) = 1
INNER JOIN dbo.Organistation O ON O.KeySubCompany = SC.KeySubCompany
GROUP BY C.KeyCompany, O.O1 WITH ROLLUP
...
to increase the signal/noise ratio (the NULL
columns are noise IMO), and reduce the length of the vertical scroll, but I refrained as not sure if this will be useful for SO.
The same thing can happen in other language if the write use extra blank line (3 or 5 instead of 1) to separate code blocks.
Is there a guideline or a common way to handle case like this?