It's the end of the year

  • It almost looks like there should be an additional radio selection, the last one.

  • Happy New Year, Steve! Thank you for all that you do for this wonderful community!

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Great question. Best wishes for everyone.

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

  • Even if it is not commented out, option four returns two values, only one of them the right one, so really guessing the intent of the is borderline impossible.

  • Xavon (1/4/2016)


    Even if it is not commented out, option four returns two values, only one of them the right one, so really guessing the intent of the is borderline impossible.

    Ah, that's the issue. Cut and pasted too much. Was only supposed to be the second one.

    The answer boxes are small, so it's hard to see longer code samples and I missed that.

    Points awarded back.

  • Cut and paste issues hit us all -- even to the experienced.

  • Aaron N. Cutshall (1/4/2016)


    Cut and paste issues hit us all -- even to the experienced.

    Especially to the experienced - the inexperienced are more likely to check things afterwards 🙂

  • Toreador (1/4/2016)


    Aaron N. Cutshall (1/4/2016)


    Cut and paste issues hit us all -- even to the experienced.

    Especially to the experienced - the inexperienced are more likely to check things afterwards 🙂

    +1 for the experienced but the proof of a good creator of QOD is to recognize it.

    So , Steve , +1 for you and thank you very much to recognize the error ( the explanation is interesting and could apply to some other "erroneous or not easily understandable QOD ).

    Anyway , I have learnt about English/us words...

  • Good question. Just one minor thing, I'd use the following the end of the calendar year:

    SELECT DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0));

  • Lynn Pettis (1/4/2016)


    Good question. Just one minor thing, I'd use the following the end of the calendar year:

    SELECT DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0));

    So short and good way...

    +1 and thanks

  • Lynn Pettis (1/4/2016)


    Good question. Just one minor thing, I'd use the following the end of the calendar year:

    SELECT DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0));

    Slow / lazy typer

    😎

    SELECT DATEFROMPARTS(YEAR(GETDATE()),12,31)

    or

    SELECT DATETIMEFROMPARTS(YEAR(GETDATE()),12,31,0,0,0,0)

  • Lynn Pettis (1/4/2016)


    Good question. Just one minor thing, I'd use the following the end of the calendar year:

    SELECT DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0));

    With the understanding that both -1's (1899-12-31) are in a year earlier than 0 (1900-01-01), you can get way with murder.

    SELECT DATEADD(yy,DATEDIFF(yy,-1,GETDATE()),-1); --Last Day of Current Year

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (1/4/2016)


    Lynn Pettis (1/4/2016)


    Good question. Just one minor thing, I'd use the following the end of the calendar year:

    SELECT DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0));

    With the understanding that both -1's (1899-12-31) are in a year earlier than 0 (1900-01-01), you can get way with murder.

    SELECT DATEADD(yy,DATEDIFF(yy,-1,GETDATE()),-1); --Last Day of Current Year

    Never imagined I would ever boost in this way but mine is (4 characters) shorter than yours:-D

    😎

    Edit: parenthesis

  • Eirikur Eiriksson (1/4/2016)


    Jeff Moden (1/4/2016)


    Lynn Pettis (1/4/2016)


    Good question. Just one minor thing, I'd use the following the end of the calendar year:

    SELECT DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0));

    With the understanding that both -1's (1899-12-31) are in a year earlier than 0 (1900-01-01), you can get way with murder.

    SELECT DATEADD(yy,DATEDIFF(yy,-1,GETDATE()),-1); --Last Day of Current Year

    Never imagined I would ever boost in this way but mine is (4 characters) shorter than yours:-D

    😎

    Edit: parenthesis

    You got me beat too.

    SELECT CAST(CAST(YEAR(GETDATE()) AS CHAR(4)) + '1231' AS DATE)



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Alvin Ramard (1/4/2016)


    Eirikur Eiriksson (1/4/2016)


    Jeff Moden (1/4/2016)


    Lynn Pettis (1/4/2016)


    Good question. Just one minor thing, I'd use the following the end of the calendar year:

    SELECT DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0));

    With the understanding that both -1's (1899-12-31) are in a year earlier than 0 (1900-01-01), you can get way with murder.

    SELECT DATEADD(yy,DATEDIFF(yy,-1,GETDATE()),-1); --Last Day of Current Year

    Never imagined I would ever boost in this way but mine is (4 characters) shorter than yours:-D

    😎

    Edit: parenthesis

    You got me beat too.

    SELECT CAST(CAST(YEAR(GETDATE()) AS CHAR(4)) + '1231' AS DATE)

    Shorter version of yours, same length as mine:Whistling:

    😎

    SELECT EOMONTH(STR(YEAR(GETDATE()))+'1231')

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

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