• Hugo Kornelis (5/24/2010)


    The reason I cheated is that the expressions used to set the two datetime variables are way too complex to understand. Especially with their (lack of) formatting. Having to scroll horizontally to see the end of an expression is never a good sign. Same goes for having to count parenthese to find out what belongs together and what doesn't. If one of my staff (which in reality I don't have) turned in this code, I'd send him/her back.

    Sorry, Hugo, but I have to disagree with you here. I was able to parse the datetime expressions without much trouble. More to the point, a more realistic scenario is that one of your staff writes this code, and you find out about it after it's either gotten to production or is ready to go there. At that point, you can fire this staff member (I don't argue that the code is hard to read) but you still have to deal with the code.

    There was nothing stopping you from pasting into SSMS (or notepad or whatever) to reformat the code so you could parse it without running it. And if that's all you did, that's certainly not cheating.

    Personally, I like this kind of question because it tests more than "do you know how SQL server assigns result datatypes?"