RSS 2.0 Feed
RSS 2.0

Atom 1.0 Feed
Atom 1.0

  Sweet Dreams Are Made of This 

I just read a new post on the Daily WTF. Although this one does raise some question of it's validity of being from real live production code, I tend to belive it because I've come across my share of completely idiotic & inane code from time to time. This one takes the cake:

CREATE PROCEDURE sp_get_order (
        @OrderID        int
) AS
select * into #temp_order from Orders
delete from #temp_order where OrderID<>@OrderID
select * from #temp_order
drop table #temp_order

Wow. Enough to leave you speechless. But really, coming across this kind of code in a client's production system is what dreams are made of. You do a fix that takes all of 3.256805 seconds to make to change this to a select * from orders where orderid = @orderid and your client sees you as a God, and rightly so ;-) because you've increased performance of their app by 200% with just a few keystrokes. But really, the developer knew how to create a temp table with the orders data, delete everything where the id was not the id he wanted and then drop the temp table, but didn't know how to do a “where orderid = @orderid”? I find that very questionable, but I hate to say I've seen code every bit as ridiculous as that from time to time.


Leave a comment below.


  1. Ryan Jameson 9/2/2004 11:14 AM
    The worst part about this is that the person who wrote that proc probably uses the title "Senior Software Engineer" on his resume. Having spent the last couple of weeks interviewing candidates for a senior level position, the harrowing truth about the level of ineptitude among developers is becoming clear.

    When it comes to professional confidence (read ego), developers rank just below professional atheletes. This guy probably thought he was the shit cause he knew how to use temp tables. He probably stormed into his manager's office asking for more money each year.

    Perhaps as a group, we ought not to be quite so proud of ourselves until we've eradicated this kind of error from our profession.

  2. Ryan Farley 9/2/2004 11:19 AM
    No kidding. This guy's resume probably is not that different than yours or mine, describing the things he knows *how* to do. The fact that he could beat out someone for a job based on this list of what he knows how to do over someone who knows *when* and *why* to do something is a downright painful thought.
  3. Milan Negovan 9/3/2004 5:57 AM
    Why I don't understand is why people don't use table variables, but use temp tables right and left. Temp tables are such a resource hog. :(
  4. Jeremy Brayton 9/3/2004 8:26 AM
    I think us decent developers should use this as a basis for raises. Print out our code, get a dailywtf version of something similar and go "See, I'm much more talented than this weinee, and they're getting paid twice as much as me!". If only the dailywtf gave you their title and salary, we could try to haggle our way up to a better pay bracket. I'm sure some of us could even upgrade our titles to "Senior Software Engineer" if one or more of these snippets of code came from one.
  5. Milan Negovan 9/3/2004 1:23 PM
    Temporary tables have been abused for way too long now. Unfortunately, few people are familiar with table variables which are a great alternative to tempdbs.
  6. Me 9/6/2004 9:30 AM
    Wow, this was really worth commenting on.
  7. Pippi 9/8/2004 8:45 PM
    off subject a little but still speaking of crazy stored procedures. Ever come across stor proc that was object oriented? Really, this app in production had only 4 very large complex stored procedures. obj_sp_account was one and if I ever get a change to see it again, I'll post it and Im wondering on performance issues. It went something like

    CREATE PROCEDURE obj_sp_account (
    @Flag varchar 1
    @otherstuff varchar 255
    @SomeID varchar 12
    ) AS
    if @flag = V then -- view object data
    select * from account where accountid = @SomeID
    if @flag = U then -- update object data
    Update something

    So what do you think... ever heard of OO design with stor proc?
  8. secretGeek 9/16/2004 4:06 PM
    I hate to defend a moron but...

    I reckon he initially had written just:

    select * from orders where orderid = @orderid

    but then he got some kind of problem that was out of his league. Perhaps he had a locking issue, or a threading problem. Possibly in some completely different part of the application. He then searched wildly for a solution, changing things in obscure ways in order to rule out possibilities.

    When the process finished he didn't undo the results of his wild goose chase.

    (I don't know exactly what he would've ruled out with the above sproc... but i suspect it might've been that he'd have a chance to isolate a snapshot of the table at the time the query was run... not sure...)

    Yeh i've done similarly bad bug-chasing practices in the past. I'm not proud, but at least I'm honest.

    I'm just saying he's probably not an idiot -- just a careless, overworked moron.

    (and no -- it wasn't me!)


  9. host 6/13/2007 11:36 AM
    Hahhahahah thats so funny. However i doubt its real
Comments have been closed on this topic.



Also see my CRM Developer blog