SQL CHOOSE

  • Calibear

    Ten Centuries

    Points: 1377

    Comments posted to this topic are about the item SQL CHOOSE

    --------
    For SQL Tips, check out my blog: http://lantztechknowledge.blogspot.com/[/url]
    You can also follow my twitter account to get daily updates: @BLantz2455

  • Raghavendra Mudugal

    SSChampion

    Points: 10658

    Good one, thank you for posting.

    (Or, the date '1931-02-29' if the year is not leap)

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

  • PRAMANA.DBA

    SSCertifiable

    Points: 5507

    Good question.. "CHOOSE" new built-in-function in SQL 2012.

  • Vinay Kumar

    SSCertifiable

    Points: 6098

    Good question. But i think this question should had topic "DateTime" rather than "SQL CHOOSE". 🙂

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

  • SQLRNNR

    SSC Guru

    Points: 281243

    Thanks for the question.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • kapil_kk

    SSC-Insane

    Points: 21316

    Thanks for the question...

    Learn about CHOOSE today 🙂

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

  • Carlo Romagnano

    SSC-Insane

    Points: 21987

    If the statement begins with

    set dateformat ymd,

    the qotd would be perfect.

  • demonfox

    SSCertifiable

    Points: 6289

    Danny Ocean (6/18/2013)


    Good question. But i think this question should had topic "DateTime" rather than "SQL CHOOSE". 🙂

    based on the explanation, I guess, you reached the conclusion. The reference reach out to Choose(T-SQL) which is nowhere mentioned in the explanation.

    Easy question though.

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

  • Richard Warr

    SSCertifiable

    Points: 6957

    I ran the code and got:

    Msg 242, Level 16, State 3, Line 7

    The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

    The statement has been terminated.

    That was in the INSERT rather than the SELECT though.

    _____________________________________________________________________
    MCSA SQL Server 2012

  • Carlo Romagnano

    SSC-Insane

    Points: 21987

    Richard Warr (6/19/2013)


    I ran the code and got:

    Msg 242, Level 16, State 3, Line 7

    The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

    The statement has been terminated.

    That was in the INSERT rather than the SELECT though.

    Re-run the code with "set dateformat ymd" first

  • malleswarareddy_m

    SSCertifiable

    Points: 5847

    Carlo Romagnano (6/19/2013)


    Richard Warr (6/19/2013)


    I ran the code and got:

    Msg 242, Level 16, State 3, Line 7

    The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

    The statement has been terminated.

    That was in the INSERT rather than the SELECT though.

    Re-run the code with "set dateformat ymd" first

    1+

    other wise remove datetime

    create table #Employee

    (

    PositionId int,

    Birthday date

    )

    insert into #Employee

    select 0, '1995-01-01'

    union all

    select 1, '1983-08-01'

    union all

    select 2, '1948-07-31'

    union all

    select 3, '1932-02-29'

    union all

    select 4, '1980-06-15'

    --Query 1

    SELECT BirthMonth = CHOOSE (Month(Birthday), 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')

    FROM #Employee

    drop table #Employee

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)

  • matthew.flower

    Default port

    Points: 1408

    It is all very well saying "re-run it with this additional line" when the returned error from the code in the question is exactly the wording of one of the wrong answers, but doesn't this just prove that as the question was framed - excluding the date format specification that both 2 and 3 were correct answers?

  • Carlo Romagnano

    SSC-Insane

    Points: 21987

    matthew.flower (6/19/2013)


    It is all very well saying "re-run it with this additional line" when the returned error from the code in the question is exactly the wording of one of the wrong answers, but doesn't this just prove that as the question was framed - excluding the date format specification that both 2 and 3 were correct answers?

    That's correct, but the qotd was about CHOOSE and not date formats.

    The installation takes as default for the date format the regional settings. For e.g. in Italy it is dmy, in U.S.A is ymd, In England ydm and so on.

  • call.copse

    SSCoach

    Points: 17206

    Nice function, didn't remember that one coming in. I'd argue that maybe for some cases CASE might still be a little clearer, if more unwieldy, but options are always good.

  • This was removed by the editor as SPAM

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

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