I am not quite used to writing very long SPs. And I found it become quickly hard to manage when working with those wide tables. Even a simple UPSERT will take very long line or tens of lines of code (I found the col/line style easier to read for me, but working with those very wide tables are really a pain for me). Gradualy I found myself start to use BEGIN/END to wrap those UPSERTs and others basic operations on the same table etc to group them into logical sections. So that in IDE they can be easily fold and unfold, to check and review with comments. Note: I am not wrting them for any control blocks. Just simple BEGIN/END to wrap them into a foldable section.
Will adding a few extra BEGIN/END to group and fold/unfold lenthy code lead to any side effect? Currently I am not seeing any yet... If so what they could they be ? Are there any better way to orgnize those code in SP ?
Oh by folding I mean
CREATE PROCEDURE/MULT_STATEMENT_FUNCTION
...
BEGIN
-- UPSERT QC records
BEGIN
UPDATE QC_SECT1 <-- fold[]
SET COL1=...
COL2=
.....
IF @@ROWCOUNT.... <--fold[ click 1]
INSERT INTO ... <-Fold[click 2]
(
COL1
....
VALUES <-Fold[click 3]
(
...
END
-- calculate distribution
BEGIN
DECLARE @GRP1_.....
DECLARE @GRP2_....
WITH .....
....
) AS PRE_CAL1 <-- fold[click 1]
) AS PRE_CAL2 <-- fold[click 2]
) AS ... <-- fold[click 3]
END
END
I found it very inconvienint to inspect long scripts, Gradually I find myself start to use BEGIN/END. In VSCode it take so many clicks to fold a single CTE statement. BEGIN/END made it a lot easier. But I really want to make sure, I am doing sth wrong.
PS: The grouping columns by line ideas are very valid, I fully agree. Regarding the col/line style. It's not that I am really fond of it. But I guess under my current situation many people probably will prefer it too. The wide tables in vendor db have long prefix to , I'd say ,group the columns. list them vertically helps to align them, so that they can be distingished easier... I guess mine currently is a special case.
Thanks.
