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.

Obviously the old code is a hideous display of incompetence what with the gratitious use of cursors (not even FAST_FORWARD at that) and temp tables in dynamic SQL no less, but I think the new code is missing an ORDER BY Graphic_number ASC, Dept_code DESC (with matching nonclustered indexes on the table) and probably could be improved by an inline table valued function with a CROSS APPLY in place of dbo.func_grOrder_GetAssigned(Order_id) and a FULLTEXT index for the Description column to avoid the non-SARGable wildcard prefix.

Sprinkle WAITFOR DELAY '00:00:01' (or a more appropriate value, do a performance analysis first; it should run faster than the old unoptimized version) judiciously across your newly optimized SPs, so you still have room for improvement.

The old one had been in production for a long while. Users knew that it returned correct results but just took too much time to run. They got timeout messages from time to time. Instead of fixing it, it was easier and quicker to write a new one.