• (cs) in reply to no u
    no u:
    I always like to ask candidates who claim to have problem solving skills and/or sql experience the following question:

    What is an sql query you could use to return (only) the largest value in a particular column without using the max function. (they have an example table in front of them which I use for other simple questions also). I don't think anyone has ever given me a correct answer.. despite it being ridiculously simple.

    I tend to start worrying about these things the moment I have to work with a database that does not have the max() function, and some interviewer asking this question would be suspect in my mind.

    Now, if he were to ask how to make a pivot table if the database at hand does not support such functionality...

  • bitburner (unregistered) in reply to boog

    anybody who is as sick of seeing crappy code like this as I am. Someone should read what Geoff is saying - maybe learn something new today and give the rest of us who already know the basics a break.

  • bitburner (unregistered) in reply to boog
    boog:
    Geoff:
    The issue is not so much that most of the code sucks (it does) but that rather letting the SQL return the number of rows, he selects the data set, and then iterates over it counting the records.

    This is all in a function so the dataset is going to go out of scope, he is not using it for anything else; its big waste, of time retrieving it. Its also worth pointing out that the adodb object has a count property. The loop is likely not needed even running the query he did, but in fairness sometime that value is not correct until the movelast() method/function gets called.

    Oh and he is using cmdtext rather than calling a procedure with position parameters, usually not ideal. I don't see any input validation but depending on where myHomeID and MyStatus are coming from that may or may not be a WTF as well.

    Who cares?

Leave a comment on “A More Better Way to Count”

Log In or post as a guest

Replying to comment #:

« Return to Article