Update with CASE statement

  • Comments posted to this topic are about the item Update with CASE statement

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.

  • As it stands, the question is poorly phrased. Even if one part of the solution is clearly false, the boolean 'OR' operation makes the statement true if the other part is true - "True or False ... 1=1 OR 1=0?" - which rather detracts from a clever example of using the CASE statement to update the column based on its current value.

    The question that follows, what would the 'FALSE' answer look like - updates the data unsuccessfully (?) OR fails, and doesn't throw an error?

  • For me the question was simple, clear and very basic. Thanks ๐Ÿ™‚

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter

  • zerko (2/18/2013)


    As it stands, the question is poorly phrased. Even if one part of the solution is clearly false, the boolean 'OR' operation makes the statement true if the other part is true - "True or False ... 1=1 OR 1=0?" - which rather detracts from a clever example of using the CASE statement to update the column based on its current value.

    The question that follows, what would the 'FALSE' answer look like - updates the data unsuccessfully (?) OR fails, and doesn't throw an error?

    I thougth OR here is english , not logical or .. and the caps were used for emphasis ..but, that what I thought..

    update woudl happen ๐Ÿ˜€

    ~ demonfox
    ___________________________________________________________________
    Wondering what I would do next , when I am done with this one :ermm:

  • simple basic question for the day...

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Seriously?.

  • Good Question. Again come to know some basic.

    keep it up.

    Thanks

    Thanks
    Vinay Kumar
    -----------------------------------------------------------------
    Keep Learning - Keep Growing !!!

  • Spent 10 minutes looking for the catch, only to realize there wasn't one.

    Thanks for the question.

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

  • demonfox (2/18/2013)


    zerko (2/18/2013)


    As it stands, the question is poorly phrased. Even if one part of the solution is clearly false, the boolean 'OR' operation makes the statement true if the other part is true - "True or False ... 1=1 OR 1=0?" - which rather detracts from a clever example of using the CASE statement to update the column based on its current value.

    The question that follows, what would the 'FALSE' answer look like - updates the data unsuccessfully (?) OR fails, and doesn't throw an error?

    I thougth OR here is english , not logical or .. and the caps were used for emphasis ..but, that what I thought..

    update woudl happen ๐Ÿ˜€

    Thank you zerko and demonfox for the comments as demonfox stated it is completely correct and I did not realize this until now, yes it is not logical, will try to do much better in my next qtod.

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.

  • The update may fails with error, if the default collation is case sensitive.

    UPDATE GenderUpdate

    SET Gender = CASE WHEN GENDER = 'M' then 'F' ELSE 'M' END

  • I like the question. Thank you!

    Best Regards,

    Chris Bรผttner

  • Not confessing to be the best a writing English, personally I use far to many abbreviated/ slang and shortened words (probably due to my age and/or regional location) but this is very poor English. ๐Ÿ˜›

    However I went with true though as the statement would work if ran. :w00t:

    Regards
    ld

    Stoke-on-Trent
    United Kingdom

    If at first you don't succeed, go to the pub and drink away your current thought plan.

  • This was removed by the editor as SPAM

  • Stewart "Arturius" Campbell (2/19/2013)


    The intent of the question is good, but the English language syntax used here had me scratching my head for a bit.

    <Rant>

    True or false requires a statement against which a judgement call must be made, e.g. the SQL command given in the snippet will update the column correctly. True or False

    Or, as a question per sรช: will the SQL command given in the snippet succeed or fail?

    </Rant>

    Don't let this discourage you from posting more questions, though. The thought process required always helps clear out cobwebs in preparation for the day.

    True - the one thing I have found is making your intent clear, without any assumptions - after all you know what you mean - you wrote it. From my experience this can be difficult enough for native English speakers - let alone in a language that is not your native tongue.

    Nice question - thanks

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. โ€• Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • A straight forward question..

    --
    Dineshbabu
    Desire to learn new things..

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

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