CodeSOD: Well, at least it compiles…:
Working on a team that is uplifting a legacy application into a newer technology, Neil K. is responsible for ensuring that the new application is working the same as the one being replaced.
While looking into the new functionality, he found the following tucked away in a stored procedure (of which this is only an exerpt). For his sake, I hope for two things. First, I hope he’s only responsible for testing it and doesn’t have to maintain this hornet’s nest of code. Second, in the name of all that is good in this world, I hope that the whomever is responsible for this mess contained their version of insanity to only one stored procedure.
SELECT @tv_100 = (@b_M – 1) + 4*(2 – @b_sd)
SELECT @tv_101 = (@b_M – 1) + 4*(2 – @b_sd)
SELECT @tv_102 = (@b_M – 1) + 4*(2 – @b_sd)
SELECT @tv_104 = (@b_M – 1) + 4*(2 – @b_sd)
SELECT @tv_109 = ((10 – @f_M) + 4*(2 – @f_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (@q3_M – 1) + 4*(2 – @q3_sd))/3
SELECT @tv_111 = ((10 – @g_M) + 4*(2 – @g_sd) + (@m_M – 1) + 4*(2 – @m_sd) + (10 – @o_M) + 4*(2 – @o_sd) + (@q1_M – 1) + 4*(2 – @q1_sd))/4
SELECT @tv_115 = ((10 – @f_M) + 4*(2 – @f_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (@q3_M – 1) + 4*(2 – @q3_sd))/3
SELECT @tv_116 = ((@b_M – 1) + 4*(2 – @b_sd) + (@f_M – 1) + 4*(2 – @f_sd) + (10 – @g_M) + 4*(2 – @g_sd) + (10 – @o_M) + 4*(2 – @o_sd))/4
SELECT @tv_118 = ((@b_M – 1) + 4*(2 – @b_sd) + (10 – @f_M) + 4*(2 – @f_sd) + (@q3_M – 1) + 4*(2 – @q3_sd))/3
SELECT @tv_122 = ((@b_M – 1) + 4*(2 – @b_sd) + (@m_M – 1) + 4*(2 – @m_sd) + (@q1_M – 1) + 4*(2 – @q1_sd))/3
SELECT @tv_123 = ((10 – @e_M) + 4*(2 – @e_sd) + (10 – @h_M) + 4*(2 – @h_sd) + (10 – @m_M) + 4*(2 – @m_sd) + (@q1_M – 1) + 4*(2 – @q1_sd))/4
SELECT @tv_125 = ((@a_M – 1) + 4*(2 – @a_sd) – 0.5*ABS(5.5 – @i_M) + (@L_M – 1) + 4*(2 – @L_sd))/2
SELECT @tv_126 = ((@b_M – 1) + 4*(2 – @b_sd) + (10 – @f_M) + 4*(2 – @f_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (@q3_M – 1) + 4*(2 – @q3_sd))/4
SELECT @tv_127 = ((10 – @f_M) + 4*(2 – @f_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (10 – @q1_M) + 4*(2 – @q1_sd) + (@q3_M – 1) + 4*(2 – @q3_sd))/4
SELECT @tv_129 = ((10 – @m_M) + 4*(2 – @m_sd) + (10 – @o_M) + 4*(2 – @o_sd) + (10 – @q1_M) + 4*(2 – @q1_sd) + (10 – @q3_M) + 4*(2 – @q3_sd))/4
SELECT @tv_131 = ((@e_M – 1) + 4*(2 – @e_sd) + (10 – @g_M) + 4*(2 – @g_sd) + (10 – @q2_M) + 4*(2 – @q2_sd))/3
SELECT @tv_132 = ((10 – @a_M) + 4*(2 – @a_sd) + (@e_M – 1) + 4*(2 – @e_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (10 – @q1_M) + 4*(2 – @q1_sd) + (@q2_M – 1) + 4*(2 – @q2_sd))/5
SELECT @tv_134 = ((@a_M – 1) + 4*(2 – @a_sd) + (10 – @c_M) + 4*(2 – @c_sd) + (10 – @g_M) + 4*(2 – @g_sd) + (@i_M – 1) + 4*(2 – @i_sd) + (10 – @L_M) + 4*(2 – @L_sd))/5
SELECT @tv_135 = ((@a_M – 1) + 4*(2 – @a_sd) + (10 – @b_M) + 4*(2 – @b_sd) + (@i_M – 1) + 4*(2 – @i_sd) + (10 – @L_M) + 4*(2 – @L_sd) + (10 – @q3_M) + 4*(2 – @q3_sd))/5
SELECT @tv_138 = ((10 – @b_M) + 4*(2 – @b_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (@q3_M – 1) + 4*(2 – @q3_sd) + (@q4_M – 1) + 4*(2 – @q4_sd))/4
SELECT @tv_139 = ((10 – @b_M) + 4*(2 – @b_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (@q3_M – 1) + 4*(2 – @q3_sd) + (@q4_M – 1) + 4*(2 – @q4_sd))/4
SELECT @tv_140 = (10 – @q3_M) + 4*(2 – @q3_sd)
SELECT @tv_141 = ((@b_M – 1) + 4*(2 – @b_sd) + (@q3_M – 1) + 4*(2 – @q3_sd))/2
SELECT @tv_143 = ((10 – @a_M) + 4*(2 – @a_sd) + (10 – @i_M) + 4*(2 – @i_sd) + (@L_M – 1) + 4*(2 – @L_sd))/3
SELECT @tv_145 = ((10 – @b_M) + 4*(2 – @b_sd) + (10 – @m_M) + 4*(2 – @m_sd) + (@o_M – 1) + 4*(2 – @o_sd) + (10 – @q1_M) + 4*(2 – @q1_sd) + (@q3_M – 1) + 4*(2 – @q3_sd))/5
SELECT @tv_146 = ((10 – @f_M) + 4*(2 – @f_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (@q3_M – 1) + 4*(2 – @q3_sd))/3
SELECT @tv_147 = ((10 – @b_M) + 4*(2 – @b_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (@q3_M – 1) + 4*(2 – @q3_sd))/3
SELECT @tv_148 = ((10 – @b_M) + 4*(2 – @b_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (@q3_M – 1) + 4*(2 – @q3_sd))/3
SELECT @tv_149 = ((@c_M – 1) + 4*(2 – @c_sd) + (10 – @q4_M) + 4*(2 – @q4_sd))/2
SELECT @tv_150 = ((@c_M – 1) + 4*(2 – @c_sd) + (10 – @q4_M) + 4*(2 – @q4_sd))/2
SELECT @tv_151 = ((@c_M – 1) + 4*(2 – @c_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (10 – @L_M) + 4*(2 – @L_sd))/3
SELECT @tv_152 = ((@c_M – 1) + 4*(2 – @c_sd) + (@g_M – 1) + 4*(2 – @g_sd) + (10 – @L_M) + 4*(2 – @L_sd))/3
SELECT @tv_153 = (10 – @q4_M) + 4*(2 – @q4_sd)
(Via The Daily WTF.)