Case Statement Update

  • MMartin1

    One Orange Chip

    Points: 27488

    Comments posted to this topic are about the item Case Statement Update

    ----------------------------------------------------
    How to post forum questions to get the best help [/url]

  • This was removed by the editor as SPAM

  • Magnus Ahlkvist

    SSC Eights!

    Points: 883

    Very good question. I got it wrong, because I couldn't (apparently) read this early in the morning 🙂

    But a very good example of where inexperienced developers tend to get things wrong with CASE.

    Sql Server blog: http://www.tsql.nu

  • Thom A

    SSC Guru

    Points: 98326

    Glad to see my brain is still working, even after waiting 2 hours for my flight, with another 4 to go! I was pretty sure it had given up when it saw the delays board >_<

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.

  • Heals

    SSCrazy

    Points: 2232

    Depends which column you're looking at, could be 1 and 3, or one of the options you listed 😀

    Ignore me - have contracted the plague overnight so my head isn't really working hehe - good question, never really had to use the syntax so learnt something new 🙂

  • RossOverThere

    SSC Veteran

    Points: 293

    Good one, which I'd have got correct if I'd remembered to read the title of the question!

  • Ed Wagner

    SSC Guru

    Points: 286958

    I had to read it twice because I was looking for the trick. Nice, straightforward question. Thanks.

  • Kaye Cahs

    SSCarpal Tunnel

    Points: 4135

    Good question - and apparently not all that easy since 45% of us got it wrong.

    Thanks.

  • akljfhnlaflkj

    SSC Guru

    Points: 76202

    Good question, thanks.

  • Revenant

    SSC-Forever

    Points: 42467

    Interesting - thank you!

  • MMartin1

    One Orange Chip

    Points: 27488

    Ed Wagner (11/1/2016)


    I had to read it twice because I was looking for the trick. Nice, straightforward question. Thanks.

    Thanks Ed. No tricks, though it is the day after Halloween :-). Simply highlighting a situation one might encounter in the normal SQL world.

    ----------------------------------------------------
    How to post forum questions to get the best help [/url]

  • Koen Verbeeck

    SSC Guru

    Points: 258938

    Somehow completely missed that the data type was bit.

    Moar caffeine needed!

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • MMartin1

    One Orange Chip

    Points: 27488

    Koen Verbeeck (11/8/2016)


    Somehow completely missed that the data type was bit.

    Moar caffeine needed!

    Ok maybe the defaulting of the bit field to 'false' is a little "bit" tricky. Part of the whole question is showing that this is possible and to look out for these things 🙂

    ----------------------------------------------------
    How to post forum questions to get the best help [/url]

  • TomThomson

    SSC Guru

    Points: 104772

    MMartin1 (11/8/2016)


    Koen Verbeeck (11/8/2016)


    Somehow completely missed that the data type was bit.

    Moar caffeine needed!

    Ok maybe the defaulting of the bit field to 'false' is a little "bit" tricky. Part of the whole question is showing that this is possible and to look out for these things 🙂

    No, that wasn't tricky really, as defaults only take effect when an insert or update doesn't specify the content of the column, and here the content is specified because the case statement provides content for that column in every row affected by the update, so the only question is what content does the case statement provide for the columns of interest.

    Unless, of course, someone imagines that a default constraint substitutes the default value for a specified NULL, which is about on a par with failing Jeff's favourite interview question.

    Tom

  • GPO

    SSCarpal Tunnel

    Points: 4450

    ...Case Statement Update...

    Shouldn't that say "case EXPRESSION update"?

    ...One of the symptoms of an approaching nervous breakdown is the belief that ones work is terribly important.... Bertrand Russell

Viewing 15 posts - 1 through 15 (of 15 total)

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