Click here to Skip to main content
15,894,720 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: 4096 Columns should be enough for anyone. Pin
Guffa29-Jul-08 1:21
Guffa29-Jul-08 1:21 
NewsRe: 4096 Columns should be enough for anyone. Pin
Natza Mitzi5-Aug-08 0:37
Natza Mitzi5-Aug-08 0:37 
GeneralRe: 4096 Columns should be enough for anyone. Pin
KarstenK5-Aug-08 1:56
mveKarstenK5-Aug-08 1:56 
GeneralRe: 4096 Columns should be enough for anyone. Pin
KarstenK6-Aug-08 2:20
mveKarstenK6-Aug-08 2:20 
GeneralRe: 4096 Columns should be enough for anyone. Pin
Natza Mitzi7-Aug-08 2:38
Natza Mitzi7-Aug-08 2:38 
GeneralRe: 4096 Columns should be enough for anyone. Pin
ToddHileHoffer14-Aug-08 7:20
ToddHileHoffer14-Aug-08 7:20 
GeneralRe: 4096 Columns should be enough for anyone. Pin
Cristian Amarie18-Aug-08 9:10
Cristian Amarie18-Aug-08 9:10 
GeneralIs this a coding horror? Pin
Mattia Locatelli23-Jul-08 4:30
Mattia Locatelli23-Jul-08 4:30 
I'm working on a project where all queries are like this one. It works perfectly but I think is quite hard to understand. What do you think is this a coding horror?
SELECT DISTINCT
 
TDB_Child.id_childtdb, 
TDB_Child.id_tdb, 
TDB_Child_Horizontal.dim5, 
ISNULL  ((SELECT description FROM TDB_ChildDesc WHERE (id_childtdb = TDB_Child.id_childtdb) AND (id_lang = @Language) AND (id_tdb = @Template) AND (id_dim = 'PDC_SINT')),'[DESC - ' + CAST(TDB_Child.id_childtdb AS nvarchar) + ']') AS childtdb_Description, 
ISNULL((SELECT description FROM TDB_ChildDesc AS TDB_ChildDesc_3 WHERE (id_childtdb = TDB_Child_Horizontal.dim5) AND (id_lang = @Language) AND (id_tdb = @Template) AND (id_dim = 'COM_PROP')), '[DESC - ' + CAST(TDB_Child_Horizontal.dim5 AS nvarchar) + ']') AS childtdb_Description2,
TDB_Child.flag, 
TDB_Child.ordine,
(SELECT ISNULL(SUM(valore), 0) AS Expr1 FROM TDB_FlatTable AS Act WHERE (dim10 LIKE @Country + '%') AND (dim1 = @Year) AND (dim6 <> 'TotaleBu') AND (dim5 = TDB_Child_Horizontal.dim5) AND (dim3 = 'R4') AND (dim8 = TDB_FlatTable.dim8) AND (dim2 = @Period)) AS R4,
(SELECT ISNULL(SUM(valore), 0) AS Expr1 FROM TDB_FlatTable AS Act WHERE (dim10 LIKE @Country + '%') AND (dim1 = @Year) AND (dim6 <> 'TotaleBu') AND (dim5 = TDB_Child_Horizontal.dim5) AND (dim3 = '3YP2008-2010') AND (dim8 = TDB_FlatTable.dim8) AND (dim2 = @Period)) AS Budget,
(SELECT ISNULL(SUM(valore), 0) AS Expr1 FROM TDB_FlatTable AS Act WHERE (dim10 LIKE @Country + '%') AND (dim1 = @Year - 1) AND (dim6 <> 'TotaleBu') AND (dim5 = TDB_Child_Horizontal.dim5) AND (dim3 = 'Consuntivo') AND (dim8 = TDB_FlatTable.dim8) AND (dim2 = @Period)) AS Consuntivo,
TDB_Child_Horizontal.Ordine2, 
CAST(0 AS NUMERIC) AS Delta 

FROM  TDB_Child 
INNER JOIN (SELECT DISTINCT TDB_Child_5.id_childtdb, TDB_H.dim5, TDB_H.Ordine2 FROM TDB_Child AS TDB_Child_5 CROSS JOIN (SELECT     id_childtdb AS dim5, ordine AS Ordine2  FROM TDB_Child AS TDB_Child_4 WHERE (id_report = 'CE') AND (id_tdb = @Template) AND (id_dim = 'COM_PROP') AND (visibile = 1)) AS TDB_H WHERE  (TDB_Child_5.id_tdb = @Template) AND (TDB_Child_5.id_dim = 'PDC_SINT') AND (TDB_Child_5.id_report = 'CE') AND (TDB_Child_5.visibile = 1)) AS TDB_Child_Horizontal ON TDB_Child.id_childtdb = TDB_Child_Horizontal.id_childtdb 
LEFT OUTER JOIN TDB_FlatTable ON TDB_Child.id_childtdb = TDB_FlatTable.dim8

WHERE
(TDB_Child.id_tdb = @Template) AND 
(TDB_Child.id_dim = 'PDC_SINT') AND 
(TDB_Child.id_report = 'CE') AND 
(TDB_Child.id_childtdb NOT IN ('Taxes', 'NetIncome', '<SPACES6>', '<SPACES7>', 'ROS')) AND (TDB_Child.visibile = 1)
UNION
SELECT
id_childtdb, 
id_tdb, 
dim5, 
childtdb_Description, 
childtdb_Description2, 
flag, 
ordine, 
CASE R4_PV WHEN 0 THEN 0 ELSE R4_GM / R4_PV * 100 END AS R4, 
CASE Budget_PV WHEN 0 THEN 0 ELSE Budget_GM / Budget_PV * 100 END AS Budget, 
CASE Consuntivo_PV WHEN 0 THEN 0 ELSE Consuntivo_GM / Consuntivo_PV * 100 END AS Consuntivo, 
Ordine2, 
CAST(0 AS NUMERIC) AS Delta
FROM (SELECT DISTINCT TDB_Child_3.id_childtdb, TDB_Child_3.id_tdb, TDB_Child_Horizontal_1.dim5, ISNULL
                                                  ((SELECT     description
                                                      FROM         TDB_ChildDesc AS TDB_ChildDesc_2
                                                      WHERE     (id_childtdb = TDB_Child_3.id_childtdb) AND (id_lang = @Language) AND (id_tdb = @Template) AND (id_dim = 'PDC_SINT')), 
                                              '[DESC - ' + CAST(TDB_Child_3.id_childtdb AS nvarchar) + ']') AS childtdb_Description, ISNULL
                                                  ((SELECT     description
                                                      FROM         TDB_ChildDesc AS TDB_ChildDesc_1
                                                      WHERE     (id_childtdb = TDB_Child_Horizontal_1.dim5) AND (id_lang = @Language) AND (id_tdb = @Template) AND 
                                                                            (id_dim = 'COM_PROP')), '[DESC - ' + CAST(TDB_Child_Horizontal_1.dim5 AS nvarchar) + ']') AS childtdb_Description2, 
                                              TDB_Child_3.flag, TDB_Child_3.ordine,
                                                  (SELECT     ISNULL(SUM(valore), 0) AS Expr1
                                                    FROM          TDB_FlatTable AS Act
                                                    WHERE      (dim10 LIKE @Country + '%') AND (dim1 = @Year) AND (dim6 <> 'TotaleBu') AND (dim5 = TDB_Child_Horizontal_1.dim5) AND 
                                                                           (dim3 = 'R4') AND (dim8 = 'ProductionValue') AND (dim2 = @Period)) AS R4_PV,
                                                  (SELECT     ISNULL(SUM(valore), 0) AS Expr1
                                                    FROM          TDB_FlatTable AS Act
                                                    WHERE      (dim10 LIKE @Country + '%') AND (dim1 = @Year) AND (dim6 <> 'TotaleBu') AND (dim5 = TDB_Child_Horizontal_1.dim5) AND 
                                                                           (dim3 = '3YP2008-2010') AND (dim8 = 'ProductionValue') AND (dim2 = @Period)) AS Budget_PV,
                                                  (SELECT     ISNULL(SUM(valore), 0) AS Expr1
                                                    FROM          TDB_FlatTable AS Act
                                                    WHERE      (dim10 LIKE @Country + '%') AND (dim1 = @Year - 1) AND (dim6 <> 'TotaleBu') AND (dim5 = TDB_Child_Horizontal_1.dim5) 
                                                                           AND (dim3 = 'Consuntivo') AND (dim8 = 'ProductionValue') AND (dim2 = @Period)) AS Consuntivo_PV,
                                                  (SELECT     ISNULL(SUM(valore), 0) AS Expr1
                                                    FROM          TDB_FlatTable AS Act
                                                    WHERE      (dim10 LIKE @Country + '%') AND (dim1 = @Year) AND (dim6 <> 'TotaleBu') AND (dim5 = TDB_Child_Horizontal_1.dim5) AND 
                                                                           (dim3 = 'R4') AND (dim8 = 'GrossOperatingMargin') AND (dim2 = @Period)) AS R4_GM,
                                                  (SELECT     ISNULL(SUM(valore), 0) AS Expr1
                                                    FROM          TDB_FlatTable AS Act
                                                    WHERE      (dim10 LIKE @Country + '%') AND (dim1 = @Year) AND (dim6 <> 'TotaleBu') AND (dim5 = TDB_Child_Horizontal_1.dim5) AND 
                                                                           (dim3 = '3YP2008-2010') AND (dim8 = 'GrossOperatingMargin') AND (dim2 = @Period)) AS Budget_GM,
                                                  (SELECT     ISNULL(SUM(valore), 0) AS Expr1
                                                    FROM          TDB_FlatTable AS Act
                                                    WHERE      (dim10 LIKE @Country + '%') AND (dim1 = @Year - 1) AND (dim6 <> 'TotaleBu') AND (dim5 = TDB_Child_Horizontal_1.dim5) 
                                                                           AND (dim3 = 'Consuntivo') AND (dim8 = 'GrossOperatingMargin') AND (dim2 = @Period)) AS Consuntivo_GM, 
                                              TDB_Child_Horizontal_1.Ordine2, CAST(0 AS NUMERIC) AS Delta
                       FROM          TDB_Child AS TDB_Child_3 INNER JOIN
                                                  (SELECT DISTINCT TDB_Child_2.id_childtdb, TDB_H_1.dim5, TDB_H_1.Ordine2
                                                    FROM          TDB_Child AS TDB_Child_2 CROSS JOIN
                                                                               (SELECT     id_childtdb AS dim5, ordine AS Ordine2
                                                                                 FROM          TDB_Child AS TDB_Child_1
                                                                                 WHERE      (id_report = 'CE') AND (id_tdb = @Template) AND (id_dim = 'COM_PROP') AND (visibile = 1)) AS TDB_H_1
                                                    WHERE      (TDB_Child_2.id_tdb = @Template) AND (TDB_Child_2.id_dim = 'PDC_SINT') AND (TDB_Child_2.id_report = 'CE') AND 
                                                                           (TDB_Child_2.visibile = 1)) AS TDB_Child_Horizontal_1 ON 
                                              TDB_Child_3.id_childtdb = TDB_Child_Horizontal_1.id_childtdb LEFT OUTER JOIN
                                              TDB_FlatTable AS TDB_FlatTable_1 ON TDB_Child_3.id_childtdb = TDB_FlatTable_1.dim8
                       WHERE      (TDB_Child_3.id_tdb = @Template) AND (TDB_Child_3.id_dim = 'PDC_SINT') AND (TDB_Child_3.id_childtdb IN ('ROS')) AND 
                                              (TDB_Child_3.id_report = 'CE') AND (TDB_Child_3.visibile = 1)) AS ROS
ORDER BY TDB_Child.ordine, TDB_Child_Horizontal.Ordine2

GeneralRe: Is this a coding horror? PinPopular
Megidolaon23-Jul-08 4:46
Megidolaon23-Jul-08 4:46 
GeneralRe: Is this a coding horror? Pin
PIEBALDconsult23-Jul-08 4:55
mvePIEBALDconsult23-Jul-08 4:55 
GeneralRe: Is this a coding horror? PinPopular
QuiJohn23-Jul-08 5:05
QuiJohn23-Jul-08 5:05 
GeneralRe: Is this a coding horror? Pin
leoinfo23-Jul-08 5:17
leoinfo23-Jul-08 5:17 
GeneralRe: Is this a coding horror? Pin
GibbleCH23-Jul-08 6:06
GibbleCH23-Jul-08 6:06 
GeneralRe: Is this a coding horror? Pin
Guffa29-Jul-08 1:06
Guffa29-Jul-08 1:06 
GeneralRe: Is this a coding horror? Pin
darkelv23-Jul-08 6:43
darkelv23-Jul-08 6:43 
GeneralRe: Is this a coding horror? Pin
StevenWalsh23-Jul-08 9:45
StevenWalsh23-Jul-08 9:45 
GeneralRe: Is this a coding horror? Pin
harold aptroot23-Jul-08 17:14
harold aptroot23-Jul-08 17:14 
GeneralRe: Is this a coding horror? Pin
Paul Conrad23-Jul-08 18:35
professionalPaul Conrad23-Jul-08 18:35 
GeneralRe: Is this a coding horror? Pin
StM0n24-Jul-08 0:19
StM0n24-Jul-08 0:19 
GeneralRe: Is this a coding horror? Pin
Guffa29-Jul-08 1:08
Guffa29-Jul-08 1:08 
GeneralRe: Is this a coding horror? Pin
Nile Hawk3-Aug-08 9:02
Nile Hawk3-Aug-08 9:02 
GeneralRe: Is this a coding horror? Pin
Mohammad Akbar4-Aug-08 18:45
professionalMohammad Akbar4-Aug-08 18:45 
GeneralRe: Is this a coding horror? Pin
ajtunbridge6-Aug-08 9:52
ajtunbridge6-Aug-08 9:52 
GeneralRe: Is this a coding horror? Pin
SciGama6-Aug-08 12:52
SciGama6-Aug-08 12:52 
GeneralRe: Is this a coding horror? Pin
Howard Richards7-Aug-08 5:00
Howard Richards7-Aug-08 5:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.