The Christmas CROSS APPLY

  • Comments posted to this topic are about the item The Christmas CROSS APPLY

  • Hi Steve, thank you for this question.

    Manie Verster
    Developer
    Johannesburg
    South Africa

    I am happy because I choose to be happy.
    I just love my job!!!

  • thanks for the nice question steve.

  • This was removed by the editor as SPAM

  • Steve, in your explanation, did you mean to say "This is offset by -1" instead of "by 1"? Or maybe by "offset" you meant the successive values of the ROWNUMBER() generated values in the CTE and not the N-1 argument of DATEADD?

    I also was looking for the gotcha!

    Rich

  • Rich Mechaber (9/28/2016)


    Steve, in your explanation, did you mean to say "This is offset by -1" instead of "by 1"? Or maybe by "offset" you meant the successive values of the ROWNUMBER() generated values in the CTE and not the N-1 argument of DATEADD?

    I also was looking for the gotcha!

    Rich

    Fair enough. The offset is by 1, but in the negative direction, but I can see why you might confuse that.

    Changed.

  • Yay. I got one right.

    Personally I'd simplify this one like this:

    SELECT

    DATEADD(YEAR, N, CONVERT(DATE, v.HolidayDate)) AS HolidayDate,

    HolidayName

    FROM (VALUES ('12/25/2016', 'Christmas Day')) AS v (HolidayDate, HolidayName)

    CROSS JOIN (VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) vTally(n);

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Yay, really witty. Thank you, Steve!

  • Nice question, thanks.

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

  • Wow, that's some crazy SQL! Thanks for the cool question, though. 🙂

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • I would never have forgiven myself if I missed this one.

    I'm just glad the date wasn't Thanksgiving.

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

Viewing 11 posts - 1 through 10 (of 10 total)

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