INSERTing datetimeoffsets

  • DamianC (11/2/2016)


    Expected 1 and 2 ; went for 2 so guessed wrong

    Now run this through, as with others, both 1 and 2 fail

    Can't see this been SQL version specific or down to settings

    Am I missing something here?

    Thanks

    Wait, are you saying you answered #2 and it was wrong? I answered #1 and it was wrong as well. When I run a test I see that #3 and #4 insert OK but both #1 and #2 fail. But the question marked both as wrong answers. So is there no correct answer?

  • Iwas Bornready (11/2/2016)


    DamianC (11/2/2016)


    Expected 1 and 2 ; went for 2 so guessed wrong

    Now run this through, as with others, both 1 and 2 fail

    Can't see this been SQL version specific or down to settings

    Am I missing something here?

    Thanks

    Wait, are you saying you answered #2 and it was wrong? I answered #1 and it was wrong as well. When I run a test I see that #3 and #4 insert OK but both #1 and #2 fail. But the question marked both as wrong answers. So is there no correct answer?

    If you answer #2 you do get it right. I think #1 just had the SELECT in the wrong place. The explanation was a bit confusing though. I'm guessing there is a follow up question coming and we got a mixture of both question's explanations.

  • J DBA (11/2/2016)


    Iwas Bornready (11/2/2016)


    DamianC (11/2/2016)


    Expected 1 and 2 ; went for 2 so guessed wrong

    Now run this through, as with others, both 1 and 2 fail

    Can't see this been SQL version specific or down to settings

    Am I missing something here?

    Thanks

    Wait, are you saying you answered #2 and it was wrong? I answered #1 and it was wrong as well. When I run a test I see that #3 and #4 insert OK but both #1 and #2 fail. But the question marked both as wrong answers. So is there no correct answer?

    If you answer #2 you do get it right. I think #1 just had the SELECT in the wrong place. The explanation was a bit confusing though. I'm guessing there is a follow up question coming and we got a mixture of both question's explanations.

    OK so I looked just a bit closer and now understand. Good question, but answer #1 just had an unfortunate syntax error, either put the SELECT in front of the CAST or remove the CAST structure altogether and it works.

    The real point was that #2 was missing either a + or a - symbol to indicate which direction the time offset is.

    J DBA

  • Makes sense j DBA

    Meant to say went for 1!

    - Damian

  • Clearly I edited an answer somewhere, causing issues. It's certainly my fault. Our interface makes checking these items hard, so I have to be extra careful, and wasn't here.

    My apologies.

    Points awarded back and the answers edited.

  • Steve Jones - SSC Editor (11/3/2016)


    Clearly I edited an answer somewhere, causing issues. It's certainly my fault. Our interface makes checking these items hard, so I have to be extra careful, and wasn't here.

    My apologies.

    Points awarded back and the answers edited.

    keep calm and never give up!

    😀

  • Thanks for the question.

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

  • Yup!

  • Steve Jones - SSC Editor (11/3/2016)


    Clearly I edited an answer somewhere, causing issues. It's certainly my fault. Our interface makes checking these items hard, so I have to be extra careful, and wasn't here.

    My apologies.

    Points awarded back and the answers edited.

    But once again, the thing isn't actually corrected - it still shows two invalid options instead of one. So those who answered later and picked the first invalid option instead of the second don't get anything awarded back. So we have both Friday (28 Oct) and the following Wednesday (Nov 2) having questions with wrong answers, both being supposedly corrected but not actually corrected, and I'm beginning to wonder if it's going to carry on the same way.

    Tom

  • TomThomson (11/10/2016)


    Steve Jones - SSC Editor (11/3/2016)


    Clearly I edited an answer somewhere, causing issues. It's certainly my fault. Our interface makes checking these items hard, so I have to be extra careful, and wasn't here.

    My apologies.

    Points awarded back and the answers edited.

    But once again, the thing isn't actually corrected - it still shows two invalid options instead of one. So those who answered later and picked the first invalid option instead of the second don't get anything awarded back. So we have both Friday (28 Oct) and the following Wednesday (Nov 2) having questions with wrong answers, both being supposedly corrected but not actually corrected, and I'm beginning to wonder if it's going to carry on the same way.

    Yeah. On the one hand, we didn't get our forum points. On the other hand... they're just forum points 😉 Either way we're still learning 🙂

  • Corrected now. checked the wrong box.

  • Corrected how?

    You're still showing two invalid answers - CAST(SELECT '20161015 08:15 -4:25' as DATETIMEOFFSET) and SELECT '20161015 08:15 2:00'.

    The solution is also confusing - the "correct answer" is option 2, but the "explanation" says option 1 is the invalid one.

  • Arrgghhh, I officially hate this question.

    I must have forgotten to hit save.

    Question:

    I have a simple table:

    CREATE TABLE TimeZoneOffsetTest

    ( mytime DATETIMEOFFSET)

    GO

    Which of these is invalid for inserting a row?

    Answers:

    a) INSERT dbo.TimeZoneOffsetTest (mytime) SELECT CAST('20161015 08:15 -4:25' as DATETIMEOFFSET)

    b) INSERT dbo.TimeZoneOffsetTest (mytime) SELECT '20161015 08:15 2:00'

    c) INSERT dbo.TimeZoneOffsetTest (mytime) SELECT CAST('20161015 08:00' as DATETIMEOFFSET)

    d) INSERT dbo.TimeZoneOffsetTest (mytime) SELECT GETDATE()

    b is invalid.

Viewing 13 posts - 16 through 27 (of 27 total)

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