Query

  • hmm, suprised to see mistakes in the question/answer. Might not bother answering them if they are not more accurately checked before being used.

  • Um, again I'll chorus with the rest:

    month(dob) in (1,2,3,4,5,8) - dob???? It doesn't exist, did you mean join_date? Sorry but you're wrong.

    datename(m,join_date) like '%a%' - fair does, I cocked up Feb being february, a very sneaky question.

  • Would it be fair that when a qotd is published and then found to be faulty, to admit that there was a mistake with the question and then cancel it? e.g. Just give everyone who answered zero points, and mark all replies as correct no matter what answer was given. Or any other method you prefer that does not mess up people's stats (and requires minimal programming!)

  • Points don't matter. QoD is supposed to fun way of learning something new (you're wrong) or prove your knowledge (you're right and awarded with points).

    Questions like this spoil the fun. Re-awarding later like the case with yobibyte doesn't make it taste better. Though it was common knowledge that kilobyte=1024 bytes does not conform to SI standard, I didn't know it was forbidden. Hard drive makers already use it, as it serves them better, software afaik uses 1024 formula.

    I prefer learning something new as it serves the fun, my work and my career better.

  • Hi all,

    In contrast to some other people in this discussion (and in many other QotD related discussions), I really don't care about points. Points are just a fun way to attract more audience to what should be a mix of fun and education. And the latter (the educational part) is what worries me when I see incorrect answers being marked as correct - and worries me even more when I see absolute bad practices being advertised as a correct answer, without even a disclaimer that this should never be done in a real system.

    If you were a DB developer in the US and you built your query around the letter a being or not being in the name of the month, I'd fire you immediately. Many other countries have better job protection, but in those other countries, this code wouldn't even pass the first tests, since most languages seem to have different letters in some of the month names. (And for the record, the code using LIKE '%a%' would also fail on any English server with a case sensitive collation, as neither April nor August contains a lowercase a character).

    The error with dob instead of hire_date is just an unfortunate error. Stuff like that happpens. It's a bit unfortunate in that people start doubting whether it's a deliberate setup to check how careful you read the answers or an oversight - but that's nothing one should worry about. If that were the only problem with today's QotD, I wouldn't even have bothered to post.

    But the date selection on a letter in a month name - that's just terrible. The following thiings are wrong with it:

    * Code relies on language settings and case sensitivity and is hence very unreliable

    * Code is unnecessary hard to understand, making future maintenance a nightmare

    * I didn't test to confirm, but I expect this code to be slower than the MONTH(...) IN (...) version.

    Once more - for the first reason alone, I'd terminate your contract immediately if I were your boss and we were in a country where there are no laws against such termination; for the latter two reasons, I would not terminate you but have a long and stern talk about coding for future maintenance and coding for performance. (And the jury is still out on whether that might be a harsher punishment that immediiate termination :D).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • I want mines too. I really agree with my friend from Argentina 🙂

    Regards

  • even under english the second query will not work if you are using a binary collation.

  • SELECT DATENAME(m,'1995-01-28 12:15:32.123')

    , DATENAME(m,'1995-02-28 12:15:32.123')

    , DATENAME(m,'1995-03-28 12:15:32.123')

    , DATENAME(m,'1995-04-28 12:15:32.123')

    , DATENAME(m,'1995-05-28 12:15:32.123')

    , DATENAME(m,'1995-06-28 12:15:32.123')

    , DATENAME(m,'1995-07-28 12:15:32.123')

    , DATENAME(m,'1995-08-28 12:15:32.123')

    , DATENAME(m,'1995-09-28 12:15:32.123')

    , DATENAME(m,'1995-10-28 12:15:32.123')

    , DATENAME(m,'1995-11-28 12:15:32.123')

    , DATENAME(m,'1995-12-28 12:15:32.123');

    Under an English environment, the above SELECT statement returns

    JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember

    Only 'January', 'February', 'March', and 'May' come with the small letter 'a'; while the capital letter 'A' in 'April' and 'August' do not satisfy the [ like '%a%' ] condition.

  • hm what is dob ? really like to know that 😀

  • Anyway, I think I'd probably use WHERE (MONTH(join_date) < 6 OR MONTH(join_date) = 8), I'm guessing it's faster than an IN statement, I can't be arsed to check though.

  • I have to agree with everyone else who posted above. The answers weren't very precise.

    I thought DOB referred to "Date of Birth" so I didn't select that answer. I also thought that the month strings were "Jan", "Feb", "Mar" etc. Given those strings, there isn't an "a" in "Feb".

    Pretty misleading...

  • Just adding my voice, too. A date of birth is not a join date.

  • It seems that the person creating the QOD has decided to go to Microsoft for the questions. This reminds of the type of questions on the certification exams. :w00t:

    MG

    "There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies."
    Tony Hoare

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.

  • You should give point to those who has selected not in the list not the other two

  • Just for the record I chose the Not in list answer, because

    a) join Date <> dob

    b) There was a syntax error in datename(m join_date) like '%a%' -- no comma after the m specifier, so it wouldn't work. I noticed the comma was there in the answer key however.

    c) is the only possible answer due to the syntax error.

    Thanks.

    -Luke.

    To help us help you read this[/url]For better help with performance problems please read this[/url]

Viewing 15 posts - 16 through 30 (of 95 total)

You must be logged in to reply to this topic. Login to reply