1 response

  1. Louis Davidson
    2012-03-15

    If you really want to see slow, try using FORMAT 🙂 It is a heck of a lot easier to code, but it is 2 orders of magnitude slower, and I didn’t even try to do the quarter computation. On just one run with only 10000 rows, it took over 4 seconds…

    RAISERROR (‘Format test’, 10, 1) WITH NOWAIT;

    SET STATISTICS TIME ON;
    SELECT SomeDate, –‘dd/MM/yyyy’
    CAST(FORMAT (SomeDate, ‘yyyy-01-01’) AS DATETIME) AS [FirstDayOfYear],
    CAST(FORMAT (SomeDate, ‘yyyy-MM-01’) AS DATETIME) AS [FirstDayOfMonth],
    DATEADD(QUARTER, DATEDIFF(QUARTER, @Base, SomeDate), @Base) AS [FirstDayOfQuarter],
    CAST(FORMAT (SomeDate, ‘yyyy-MM-dd HH:00:00’) AS DATETIME) AS StartOfHour,
    CAST(FORMAT (SomeDate, ‘yyyy-MM-dd HH:mm:00’) AS DATETIME) AS StartOfMinute,
    CAST(FORMAT (SomeDate, ‘yyyy-MM-d HH:mm:ss’) AS DATETIME) AS StartOfSecond
    INTO #test3
    FROM dbo.DateTest;
    SET STATISTICS TIME OFF;

    Reply

Leave a Reply to let me know how you liked this post

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top
mobile desktop