Stairway to Advanced T-SQL Level 9: Compare, Modify, Derive and Validate Date and Time Values

  • Jack 49290 - Thursday, March 30, 2017 3:45 PM

    Can you please elaborate onQ1?  Based on the chart at the top, the shortest a DATETIMEOFFSET can be is 8 and the longest aDATETIME2 can be is 8 so “AT BEST†they are equal.

    Apparently, this author doesn't respond to questions about his articles.

    DATETIME2(3) and DATETIME2(4) both only take 7 bytes.  DATETIME takes 8 bytes.  DATETIMEOFFSET(3) and DATETIMEOFFSET(4) both take 9 bytes.  Answer "B" is NOT the correct answer to the question.  Answer "C" is the correct answer.

    --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)

  • Incorrect answer to the first question. See:

    declare @dt datetime = getdate(), @dt2 datetime2(3) = sysdatetime(), @DtOff datetimeoffset(3) = SysDateTimeOffset()

    select datalength(@Dt) as [datetime], datalength(@Dt2) as [datetime2(3)], datalength(@DtOff) as [datetimeoffset(3)]

    MORE space is C!

    Захват664

    Microsoft SQL Server 2016 (SP2) (KB4052908) - 13.0.5026.0 (X64)

  • Incorrect answer to the first question. See:

    declare @dt datetime = getdate(), @dt2 datetime2(3) = sysdatetime(), @DtOff datetimeoffset(3) = SysDateTimeOffset()

    select datalength(@Dt) as [datetime], datalength(@Dt2) as [datetime2(3)], datalength(@DtOff) as [datetimeoffset(3)]

    MORE space is C!

    Захват664

    Microsoft SQL Server 2016 (SP2) (KB4052908) - 13.0.5026.0 (X64)

Viewing 3 posts - 16 through 17 (of 17 total)

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