• Jeff Moden (12/21/2008)


    timothyawiseman (12/21/2008)


    Two things of note though are that it is sometimes faster to code the procedural solution than it is to code the set based one, largely due to habit. It is sometimes the case that that savings in programmer time is far more valuable than the processing speed given up, especially if it is a script being written for one time use.

    I'm not sure why people think that way... if you practice piano, you don't practice hitting the wrong notes. Once someone knows it, writing set based code is typically faster than writting procedural code if for no other reason than it's usually shorter.

    You have a good point, and one I normally agree with, but for those of us that did procedural programming long before we picked up SQL and still do procedural (and OO, haven't tried functional yet, at least not strictly functional like Lisp or Haskell...) in addition to SQL the procedural answer often comes more easily than the set based one.

    So when I have the time, I always think through the set based solution for SQL, but I have no hesitation to just jot out the procedural version one time and be done with it if deadlines loom nigh.

    And the piano analogy is not perfect there. If you are playing the piano and hit the wrong note it sounds bad and the final product (the music) is markedly flawed. If you are writing code and you write a suboptimal piece of code, it is suboptimal not wrong. The end user may never know, especially if the final product is a spreadsheet with analysis and they never see either the code or its running process.

    ---
    Timothy A Wiseman
    SQL Blog: http://timothyawiseman.wordpress.com/