• Craig Farrell (12/10/2010)


    Plenty of hope, I've been at this ten years or so, Wayne longer. Give yourself time. Eventually you remember the functions offhand and then start coming up with strange and interesting ways to twist them together like burnt pretzels. 🙂

    And, now that you understand what's going on here... you'll never forget it. So, you've been exposed to dateadd(datediff) to get the first of the month (change the datepart to get the first of any period!), and using reverse/stuff/reverse. Not too bad for one thread!

    EDIT: Check out the common date/time routines link in my signature!

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2